Java Code Examples for com.google.api.services.sheets.v4.model.ValueRange#setRange()

The following examples show how to use com.google.api.services.sheets.v4.model.ValueRange#setRange() . 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: GoogleSheetsRetrieveValuesCustomizerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAfterProducerColumnDimension() throws Exception {
    String range = "A1:A5";
    String sheetName = "Sheet1";
    String majorDimension = RangeCoordinate.DIMENSION_COLUMNS;

    List<List<Object>> values = Collections.singletonList(Arrays.asList("a1", "a2", "a3", "a4", "a5"));
    List<String> expectedValueModel = Collections.singletonList("{\"spreadsheetId\":\"%s\", \"#1\":\"a1\",\"#2\":\"a2\",\"#3\":\"a3\",\"#4\":\"a4\",\"#5\":\"a5\"}");

    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().getAfterProducer().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 2
Source File: GoogleSheetsNamedColumnsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetValuesCustomizer() throws Exception {
    Map<String, Object> options = new HashMap<>();
    options.put("spreadsheetId", getSpreadsheetId());
    options.put("range", range);
    options.put("columnNames", columnNames);
    options.put("splitResults", false);

    GoogleSheetsGetValuesCustomizer customizer = new GoogleSheetsGetValuesCustomizer();
    customizer.customize(getComponent(), options);

    Exchange inbound = new DefaultExchange(createCamelContext());

    ValueRange valueRange = new ValueRange();
    valueRange.setRange(range);
    valueRange.setMajorDimension(RangeCoordinate.DIMENSION_ROWS);
    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> body = inbound.getIn().getBody(List.class);
    Assert.assertEquals(model.size(), body.size());
    Iterator<String> modelIterator = body.iterator();
    for (String expected : model) {
        assertThatJson(modelIterator.next()).isEqualTo(String.format(expected, getSpreadsheetId()));
    }
}
 
Example 3
Source File: GoogleSheetsGetValuesCustomizerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: GoogleSheetsRetrieveValuesCustomizerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testAfterProducerRowDimension() throws Exception {
    String range = "A1:A5";
    String sheetName = "Sheet1";
    String majorDimension = RangeCoordinate.DIMENSION_ROWS;

    List<List<Object>> values = Arrays.asList(Collections.singletonList("a1"),
            Collections.singletonList("a2"),
            Collections.singletonList("a3"),
            Collections.singletonList("a4"),
            Collections.singletonList("a5"));

    List<String> expectedValueModel = Arrays.asList("{\"spreadsheetId\":\"%s\", \"A\":\"a1\"}",
            "{\"spreadsheetId\":\"%s\", \"A\":\"a2\"}",
            "{\"spreadsheetId\":\"%s\", \"A\":\"a3\"}",
            "{\"spreadsheetId\":\"%s\", \"A\":\"a4\"}",
            "{\"spreadsheetId\":\"%s\", \"A\":\"a5\"}");


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