コード例 #1
0
  @Test
  public void testCreate() throws Exception {
    String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";

    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);

    ArgumentCaptor<DataPayload> payloadArgument = ArgumentCaptor.forClass(DataPayload.class);
    Mockito.stub(connection.create(payloadArgument.capture())).toReturn(23);

    DirectQueryExecution execution =
        (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();

    Mockito.verify(connection).create(payloadArgument.capture());

    assertEquals("pk", payloadArgument.getValue().getID());
    assertEquals("table", payloadArgument.getValue().getType());
    assertEquals(3, payloadArgument.getValue().getMessageElements().size());

    assertArrayEquals(new Object[] {23}, (Object[]) execution.next().get(0));
  }
コード例 #2
0
  @Test
  public void testSearch() throws Exception {
    String input =
        "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";

    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);

    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(qr.isDone()).toReturn(true);

    ArrayList<SObject> results = new ArrayList<SObject>();
    ArrayList<Object> values = new ArrayList<Object>();

    SObject s = Mockito.mock(SObject.class);
    // Mockito.stub(s.getId()).toReturn("theID");
    Mockito.stub(s.getType()).toReturn("Account");
    results.add(s);

    Element e1 = Mockito.mock(Element.class);
    Mockito.stub(e1.getTextContent()).toReturn("The ID");
    values.add(e1);

    Element e2 = Mockito.mock(Element.class);
    Mockito.stub(e2.getTextContent()).toReturn("The Type");
    values.add(e2);

    Element e3 = Mockito.mock(Element.class);
    Mockito.stub(e3.getTextContent()).toReturn("The Name");
    values.add(e3);

    Mockito.stub(s.getAny()).toReturn(values);
    Mockito.stub(qr.getRecords()).toReturn(results);
    Mockito.stub(
            connection.query(
                "SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false))
        .toReturn(qr);

    DirectQueryExecution execution =
        (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();

    Mockito.verify(connection, Mockito.times(1))
        .query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);

    assertArrayEquals(
        new Object[] {"The ID", "The Type", "The Name"}, (Object[]) execution.next().get(0));
  }
コード例 #3
0
  @Test
  public void testDelete() throws Exception {
    String input = "exec native('delete;', 'id1','id2')";

    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);

    ArgumentCaptor<String[]> payloadArgument = ArgumentCaptor.forClass(String[].class);
    Mockito.stub(connection.delete(payloadArgument.capture())).toReturn(23);

    DirectQueryExecution execution =
        (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();

    Mockito.verify(connection, Mockito.times(1)).delete(payloadArgument.capture());

    assertEquals("id1", payloadArgument.getValue()[0]);
    assertEquals("id2", payloadArgument.getValue()[1]);

    assertArrayEquals(new Object[] {23}, (Object[]) execution.next().get(0));
  }