org.apache.camel.support.DefaultExchange Java Examples
The following examples show how to use
org.apache.camel.support.DefaultExchange.
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: ReactorIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testToStream() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() { from("reactive-streams:reactive") .setBody().constant("123"); } }); camelctx.start(); try { CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx); Publisher<Exchange> publisher = crs.toStream("reactive", new DefaultExchange(camelctx)); Exchange res = Flux.from(publisher).blockFirst(); Assert.assertNotNull(res); String content = res.getIn().getBody(String.class); Assert.assertNotNull(content); Assert.assertEquals("123", content); } finally { camelctx.close(); } }
Example #2
Source File: GoogleSheetsCreateSpreadsheetCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("title", "SyndesisTest"); options.put("timeZone", "America/New_York"); options.put("locale", "en"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("create", ConnectorOptions.extractOption(options, "methodName")); Spreadsheet spreadsheet = (Spreadsheet) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "content"); Assert.assertNull(spreadsheet.getSpreadsheetId()); Assert.assertEquals("SyndesisTest", spreadsheet.getProperties().getTitle()); Assert.assertEquals("America/New_York", spreadsheet.getProperties().getTimeZone()); Assert.assertEquals("en", spreadsheet.getProperties().getLocale()); Assert.assertNull(spreadsheet.getSheets()); }
Example #3
Source File: GoogleSheetsAppendValuesCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("range", "A1"); options.put("valueInputOption", "RAW"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("append", ConnectorOptions.extractOption(options, "methodName")); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals("A1", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("RAW", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(0L, valueRange.getValues().size()); }
Example #4
Source File: GoogleSheetsRetrieveValuesCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("range", "A1"); options.put("majorDimension", RangeCoordinate.DIMENSION_ROWS); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("get", ConnectorOptions.extractOption(options, "methodName")); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "spreadsheetId")); Assert.assertEquals("A1", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range")); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "majorDimension")); }
Example #5
Source File: BoxDownloadCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testAfterProducer() throws Exception { String id = "12345"; String content = "Test content: åäö"; String encoding = StandardCharsets.ISO_8859_1.name(); int size = content.getBytes(encoding).length; Map<String, Object> options = new HashMap<>(); options.put("fileId", id); options.put("encoding", encoding); customizer.customize(component, options); Exchange inbound = new DefaultExchange(createCamelContext()); setBody(inbound, content, encoding); component.getAfterProducer().process(inbound); BoxFile file = inbound.getIn().getBody(BoxFile.class); assertNotNull(file); assertEquals(id, file.getId()); assertEquals(content, file.getContent()); assertEquals(size, file.getSize()); }
Example #6
Source File: GoogleSheetsNamedColumnsTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testUpdateValuesCustomizer() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("columnNames", columnNames); options.put("range", range); GoogleSheetsUpdateValuesCustomizer customizer = new GoogleSheetsUpdateValuesCustomizer(); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assertions.assertThat(inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)).isEqualTo(range); Assertions.assertThat(inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)).isEqualTo(RangeCoordinate.DIMENSION_ROWS); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assertions.assertThat(valueRange.getValues()).hasSize(values.size()); for (List<Object> rowValues : values) { Assertions.assertThat(valueRange.getValues()).contains(rowValues); } }
Example #7
Source File: GoogleSheetsGetValuesSplitResultsCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeConsumer() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("range", range); options.put("splitResults", true); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setHeader(GoogleSheetsStreamConstants.RANGE, sheetName + "!" + range); inbound.getIn().setHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION, majorDimension); inbound.getIn().setHeader(GoogleSheetsStreamConstants.RANGE_INDEX, 1); inbound.getIn().setHeader(GoogleSheetsStreamConstants.VALUE_INDEX, 1); inbound.getIn().setBody(values); getComponent().getBeforeConsumer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("get", ConnectorOptions.extractOption(options, "methodName")); String model = inbound.getIn().getBody(String.class); assertThatJson(model).isEqualTo(String.format(expectedValueModel, getSpreadsheetId())); }
Example #8
Source File: GoogleSheetsUpdateValuesCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("range", "A1"); options.put("valueInputOption", "RAW"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("update", ConnectorOptions.extractOption(options, "methodName")); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals("A1", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("RAW", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(0L, valueRange.getValues().size()); }
Example #9
Source File: KuduCreateTableCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("columns", "Integer,id;String,title;String,name;String,lastname"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Schema schema = (Schema) inbound.getIn().getHeader("Schema"); CreateTableOptions builder = (CreateTableOptions) inbound.getIn().getHeader("TableOptions"); Assert.assertNotNull(schema); Assert.assertNotNull(builder); Assert.assertEquals("Table schema has all elements", 4, schema.getColumnCount()); Assert.assertEquals("Name of the first column matches", "id", schema.getColumn("id").getName()); Assert.assertEquals("Type of the first column matches", "int32", schema.getColumn("id").getType().getName()); Assert.assertEquals("Name of the first column matches", "name", schema.getColumn("name").getName()); Assert.assertEquals("Type of the first column matches", "string", schema.getColumn("name").getType().getName()); }
Example #10
Source File: KuduScanCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Ignore public void testBeforeConsumer() throws Exception { final Map<String, Object> options = new HashMap<>(); customizer.customize(getComponent(), options); final KuduTable table = connection.openTable("impala::default.syndesis_todo"); final List<String> projectColumns = new ArrayList<>(1); final Iterator<ColumnSchema> columns = table.getSchema().getColumns().iterator(); while (columns.hasNext()) { projectColumns.add(columns.next().getName()); } final KuduScanner scanner = connection.newScannerBuilder(table) .setProjectedColumnNames(projectColumns) .build(); final Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(scanner); getComponent().getBeforeConsumer().process(inbound); }
Example #11
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testJsonTypeTargetProcessingEmptyList() throws Exception { Exchange exchange = new DefaultExchange(camelContext); exchange.getIn().setBody("[]"); new DataMapperStepHandler.JsonTypeTargetProcessor().process(exchange); assertThat(exchange.getIn().getBody(String.class)).isEqualTo("[]"); exchange.setProperty(DataMapperStepHandler.DATA_MAPPER_AUTO_CONVERSION, true); exchange.getIn().setBody("[]"); new DataMapperStepHandler.JsonTypeTargetProcessor().process(exchange); List<?> processedBody = exchange.getIn().getBody(List.class); assertThat(processedBody).hasSize(0); }
Example #12
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testJsonTypeTargetProcessing() throws Exception { Exchange exchange = new DefaultExchange(camelContext); exchange.getIn().setBody("[{\"name\": \"Bernadette\", \"age\": 27},{\"name\": \"Penny\", \"age\": 29}]"); new DataMapperStepHandler.JsonTypeTargetProcessor().process(exchange); assertThat(exchange.getIn().getBody(String.class)).isEqualTo("[{\"name\": \"Bernadette\", \"age\": 27},{\"name\": \"Penny\", \"age\": 29}]"); exchange.setProperty(DataMapperStepHandler.DATA_MAPPER_AUTO_CONVERSION, true); exchange.getIn().setBody("[{\"name\": \"Bernadette\", \"age\": 27},{\"name\": \"Penny\", \"age\": 29}]"); new DataMapperStepHandler.JsonTypeTargetProcessor().process(exchange); List<String> jsonBeans = exchange.getIn().getBody(List.class); assertThat(jsonBeans).isEqualTo(Arrays.asList("{\"name\":\"Bernadette\",\"age\":27}", "{\"name\":\"Penny\",\"age\":29}")); }
Example #13
Source File: CamelSinkTask.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
@Override public void put(Collection<SinkRecord> sinkRecords) { for (SinkRecord record : sinkRecords) { TaskHelper.logRecordContent(LOG, record, config); Map<String, Object> headers = new HashMap<String, Object>(); Exchange exchange = new DefaultExchange(producer.getCamelContext()); headers.put(KAFKA_RECORD_KEY_HEADER, record.key()); for (Iterator<Header> iterator = record.headers().iterator(); iterator.hasNext();) { Header header = (Header)iterator.next(); if (header.key().startsWith(HEADER_CAMEL_PREFIX)) { addHeader(headers, header); } else if (header.key().startsWith(PROPERTY_CAMEL_PREFIX)) { addProperty(exchange, header); } } exchange.getMessage().setHeaders(headers); exchange.getMessage().setBody(record.value()); LOG.debug("Sending exchange {} to {}", exchange.getExchangeId(), LOCAL_URL); producer.send(LOCAL_URL, exchange); if (exchange.isFailed()) { throw new ConnectException("Exchange delivery has failed!", exchange.getException()); } } }
Example #14
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testJsonTypeSourceProcessing() throws Exception { Exchange exchange = new DefaultExchange(camelContext); Map<String, Message> captured = new HashMap<>(); Message m1 = new DefaultMessage(camelContext); m1.setBody(Arrays.asList("{\"name\": \"Howard\", \"age\": 29}", "{\"name\": \"Sheldon\", \"age\": 30}")); captured.put("m1", m1); Message m2 = new DefaultMessage(camelContext); m2.setBody("{\"something\": \"else\"}"); captured.put("m2", m2); exchange.setProperty(OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP, captured); new DataMapperStepHandler.JsonTypeSourceProcessor(Arrays.asList("m1", "m2"), 2).process(exchange); assertThat(captured.get("m1").getBody(String.class)).isEqualTo("[{\"name\": \"Howard\", \"age\": 29},{\"name\": \"Sheldon\", \"age\": 30}]"); assertThat(captured.get("m2").getBody(String.class)).isEqualTo("{\"something\": \"else\"}"); }
Example #15
Source File: KuduInsertCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); String model = "{" + "\"id\": " + 5 + "," + "\"title\": \"Mr.\"," + "\"name\": \"Samuel\"," + "\"lastname\": \"Smith\"," + "\"address\": \"4359 Plainfield Avenue\"" + "}"; Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Map<?, ?> body = inbound.getIn().getMandatoryBody(Map.class); Assert.assertEquals("The row has the expected elements", 5, body.size()); Assert.assertEquals("First element of the row is an integer", 5, body.get("id")); Assert.assertEquals("Second element of the row is the title", "Mr.", body.get("title")); }
Example #16
Source File: GoogleSheetsUpdateValuesCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBeforeProducerWithJsonObject() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("range", "A1:B2"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); String body = "{\"spreadsheetId\": \"" + getSpreadsheetId() + "\", \"A\": \"a1\", \"B\": \"b1\" }"; inbound.getIn().setBody(body); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals("A1:B2", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("USER_ENTERED", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(1L, valueRange.getValues().size()); Assert.assertEquals(2L, valueRange.getValues().get(0).size()); Assert.assertEquals("a1", valueRange.getValues().get(0).get(0)); Assert.assertEquals("b1", valueRange.getValues().get(0).get(1)); }
Example #17
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testCustomValueGroupFunction() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GooglePivotTable model = new GooglePivotTable(); model.setStart("C12"); model.setSpreadsheetId(getSpreadsheetId()); model.setSourceRange("A1:D10"); GooglePivotTable.ValueGroup valueGroup = new GooglePivotTable.ValueGroup(); valueGroup.setSourceColumn("E"); valueGroup.setFunction("AVERAGE"); model.setValueGroups(Collections.singletonList(valueGroup)); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(2), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(11), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); Assert.assertEquals(1, pivotTable.getValues().size()); Assert.assertEquals("AVERAGE", pivotTable.getValues().get(0).getSummarizeFunction()); Assert.assertEquals(Integer.valueOf(4), pivotTable.getValues().get(0).getSourceColumnOffset()); }
Example #18
Source File: KuduInsertCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testAfterProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); String json = "{" + "\"id\": " + 5 + "," + "\"title\": \"Mr.\"," + "\"name\": \"Samuel\"," + "\"lastname\": \"Smith\"," + "\"address\": \"4359 Plainfield Avenue\"" + "}"; Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(json); getComponent().getAfterProducer().process(inbound); String model = (String) inbound.getIn().getBody(); Assert.assertNotNull("Model is not null", model); Map<String, Object> modelMap = JsonUtils.reader().forType(Map.class).readValue(model); Assert.assertEquals("Model has all elements", 5, modelMap.size()); Assert.assertEquals("First element is the id", 5, modelMap.get("id")); Assert.assertEquals("Third element is the name", "Samuel", modelMap.get("name")); }
Example #19
Source File: KuduCreateTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); KuduTable model = new KuduTable(); model.setName("KuduTestTable"); KuduTable.Schema modelSchema = new KuduTable.Schema(); KuduTable.ColumnSchema[] modelSchemaColumns = { new KuduTable.ColumnSchema("id", "Integer", true), new KuduTable.ColumnSchema("title", "String", false), new KuduTable.ColumnSchema("name", "String", false), new KuduTable.ColumnSchema("lastname", "String", false) }; modelSchema.setColumns(modelSchemaColumns, true); model.setSchema(modelSchema); Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Schema schema = (Schema) inbound.getIn().getHeader("Schema"); CreateTableOptions builder = (CreateTableOptions) inbound.getIn().getHeader("TableOptions"); Assert.assertNotNull(schema); Assert.assertNotNull(builder); Assert.assertEquals("Table schema has all elements", 4, schema.getColumnCount()); Assert.assertEquals("Name of the first column matches", "id", schema.getColumn("id").getName()); Assert.assertEquals("Type of the first column matches", "int32", schema.getColumn("id").getType().getName()); Assert.assertEquals("Name of the first column matches", "name", schema.getColumn("name").getName()); Assert.assertEquals("Type of the first column matches", "string", schema.getColumn("name").getType().getName()); }
Example #20
Source File: KuduCreateTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testAfterProducerFromModel() throws Exception { customizer.customize(getComponent(), new HashMap<>()); KuduTable model = new KuduTable(); model.setName("KuduTestTable"); KuduTable.Schema modelSchema = new KuduTable.Schema(); KuduTable.ColumnSchema[] modelSchemaColumns = { new KuduTable.ColumnSchema("id", "Integer", true), new KuduTable.ColumnSchema("title", "String", false), new KuduTable.ColumnSchema("name", "String", false), new KuduTable.ColumnSchema("lastname", "String", false) }; modelSchema.setColumns(modelSchemaColumns, true); model.setSchema(modelSchema); Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(model); getComponent().getAfterProducer().process(inbound); KuduTable table = (KuduTable) inbound.getIn().getBody(); Assert.assertNotNull(table); Assert.assertEquals("Table name matches", "KuduTestTable", table.getName()); Assert.assertEquals("Right ammount of columns", 4, table.getSchema().getColumns().length); }
Example #21
Source File: DataShapeCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void shouldUnmarshallToSpecifiedOutputType() throws Exception { final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject"); final Exchange exchange = new DefaultExchange(context); final Message out = exchange.getIn(); out.setBody("{}"); component.getAfterProducer().process(exchange); Assertions.assertThat(out.getBody()).isInstanceOf(AbstractDTOBase.class); }
Example #22
Source File: GoogleSheetsAppendValuesCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerRowDimension() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("range", "A1:B1"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); String model = "{" + "\"spreadsheetId\": \"" + getSpreadsheetId() + "\"," + "\"A\": \"a1\"," + "\"B\": \"b1\"" + "}"; inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("append", ConnectorOptions.extractOption(options, "methodName")); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals("A1:B1", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("USER_ENTERED", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(1L, valueRange.getValues().size()); Assert.assertEquals("a1", valueRange.getValues().get(0).get(0)); Assert.assertEquals("b1", valueRange.getValues().get(0).get(1)); }
Example #23
Source File: GoogleSheetsUpdateValuesCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerWithJsonArray() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("range", "A1:B2"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); String body = "[{" + "\"spreadsheetId\": \"" + getSpreadsheetId() + "\"," + "\"A\": \"a1\"," + "\"B\": \"b1\"" + "}," + "{" + "\"spreadsheetId\": \"" + getSpreadsheetId() + "\"," + "\"A\": \"a2\"," + "\"B\": \"b2\"" + "}]"; inbound.getIn().setBody(body); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals("A1:B2", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("USER_ENTERED", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(2L, valueRange.getValues().size()); Assert.assertEquals(2L, valueRange.getValues().get(0).size()); Assert.assertEquals("a1", valueRange.getValues().get(0).get(0)); Assert.assertEquals("b1", valueRange.getValues().get(0).get(1)); Assert.assertEquals(2L, valueRange.getValues().get(1).size()); Assert.assertEquals("a2", valueRange.getValues().get(1).get(0)); Assert.assertEquals("b2", valueRange.getValues().get(1).get(1)); }
Example #24
Source File: GoogleSheetsUpdateValuesCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerMultipleRows() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("range", "A1:B2"); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); List<String> model = Arrays.asList("{" + "\"spreadsheetId\": \"" + getSpreadsheetId() + "\"," + "\"A\": \"a1\"," + "\"B\": \"b1\"" + "}", "{" + "\"spreadsheetId\": \"" + getSpreadsheetId() + "\"," + "\"A\": \"a2\"," + "\"B\": \"b2\"" + "}"); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals("A1:B2", inbound.getIn().getHeader(GoogleSheetsStreamConstants.RANGE)); Assert.assertEquals(RangeCoordinate.DIMENSION_ROWS, inbound.getIn().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION)); Assert.assertEquals("USER_ENTERED", inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "valueInputOption")); ValueRange valueRange = (ValueRange) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "values"); Assert.assertEquals(2L, valueRange.getValues().size()); Assert.assertEquals(2L, valueRange.getValues().get(0).size()); Assert.assertEquals("a1", valueRange.getValues().get(0).get(0)); Assert.assertEquals("b1", valueRange.getValues().get(0).get(1)); Assert.assertEquals(2L, valueRange.getValues().get(1).size()); Assert.assertEquals("a2", valueRange.getValues().get(1).get(0)); Assert.assertEquals("b2", valueRange.getValues().get(1).get(1)); }
Example #25
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testCustomValueGroupFormula() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GooglePivotTable model = new GooglePivotTable(); model.setSpreadsheetId(getSpreadsheetId()); model.setSourceRange("A1:D10"); GooglePivotTable.ValueGroup valueGroup = new GooglePivotTable.ValueGroup(); valueGroup.setSourceColumn("A"); valueGroup.setFormula("=Cost*SUM(Quantity)"); model.setValueGroups(Collections.singletonList(valueGroup)); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(5), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); Assert.assertEquals(1, pivotTable.getValues().size()); Assert.assertEquals("CUSTOM", pivotTable.getValues().get(0).getSummarizeFunction()); Assert.assertEquals("=Cost*SUM(Quantity)", pivotTable.getValues().get(0).getFormula()); Assert.assertNull(pivotTable.getValues().get(0).getSourceColumnOffset()); }
Example #26
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testExplicitPivotTableStart() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GooglePivotTable model = new GooglePivotTable(); model.setStart("C12"); model.setSpreadsheetId(getSpreadsheetId()); model.setSourceRange("A1:D10"); model.setValueGroups(Collections.singletonList(sampleValueGroup())); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(2), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(11), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); assertSampleValueGroup(pivotTable); }
Example #27
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testDivergingSourceAndTargetSheetsWithExplicitStart() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GooglePivotTable model = new GooglePivotTable(); model.setStart("E10"); model.setSpreadsheetId(getSpreadsheetId()); model.setSourceSheetId(1); model.setSheetId(0); model.setSourceRange("A1:D10"); model.setValueGroups(Collections.singletonList(sampleValueGroup())); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(4), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(9), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); assertSampleValueGroup(pivotTable); }
Example #28
Source File: GoogleSheetsGetValuesCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeConsumer() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); options.put("range", range); options.put("splitResults", false); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); ValueRange valueRange = new ValueRange(); valueRange.setRange(sheetName + "!" + range); valueRange.setMajorDimension(majorDimension); valueRange.setValues(values); inbound.getIn().setBody(valueRange); getComponent().getBeforeConsumer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsValuesApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("get", ConnectorOptions.extractOption(options, "methodName")); @SuppressWarnings("unchecked") List<String> model = inbound.getIn().getBody(List.class); Assert.assertEquals(expectedValueModel.size(), model.size()); Iterator<String> modelIterator = model.iterator(); for (String expected : expectedValueModel) { assertThatJson(modelIterator.next()).isEqualTo(String.format(expected, getSpreadsheetId())); } }
Example #29
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testDivergingSourceAndTargetSheets() throws Exception { customizer.customize(getComponent(), new HashMap<>()); Exchange inbound = new DefaultExchange(createCamelContext()); GooglePivotTable model = new GooglePivotTable(); model.setSpreadsheetId(getSpreadsheetId()); model.setSourceSheetId(0); model.setSheetId(1); model.setSourceRange("A1:D10"); model.setValueGroups(Collections.singletonList(sampleValueGroup())); inbound.getIn().setBody(model); getComponent().getBeforeProducer().process(inbound); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(model.getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals(Integer.valueOf(1), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); assertSampleValueGroup(pivotTable); }
Example #30
Source File: GoogleSheetsAddPivotTableCustomizerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testBeforeProducerFromOptions() throws Exception { Map<String, Object> options = new HashMap<>(); options.put("spreadsheetId", getSpreadsheetId()); customizer.customize(getComponent(), options); Exchange inbound = new DefaultExchange(createCamelContext()); getComponent().getBeforeProducer().process(inbound); Assert.assertEquals(GoogleSheetsApiCollection.getCollection().getApiName(SheetsSpreadsheetsApiMethod.class).getName(), ConnectorOptions.extractOption(options, "apiName")); Assert.assertEquals("batchUpdate", ConnectorOptions.extractOption(options, "methodName")); Assert.assertNotNull(inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); Assert.assertEquals(getSpreadsheetId(), inbound.getIn().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID)); BatchUpdateSpreadsheetRequest batchUpdateRequest = (BatchUpdateSpreadsheetRequest) inbound.getIn().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "batchUpdateSpreadsheetRequest"); Assert.assertEquals(1, batchUpdateRequest.getRequests().size()); UpdateCellsRequest updateCellsRequest = batchUpdateRequest.getRequests().get(0).getUpdateCells(); Assert.assertEquals("pivotTable", updateCellsRequest.getFields()); Assert.assertNotNull(updateCellsRequest.getStart()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getSheetId()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getColumnIndex()); Assert.assertEquals(Integer.valueOf(0), updateCellsRequest.getStart().getRowIndex()); PivotTable pivotTable = updateCellsRequest.getRows().get(0).getValues().get(0).getPivotTable(); Assert.assertNotNull(pivotTable); Assert.assertNull(pivotTable.getSource()); Assert.assertNull(pivotTable.getRows()); Assert.assertNull(pivotTable.getColumns()); Assert.assertNull(pivotTable.getValues()); }