Search in sources :

Example 1 with Builder

use of com.google.api.ads.common.lib.client.RequestInfo.Builder in project googleads-java-lib by googleads.

the class RequestInfoXPathSetTest method testParseTransformException.

@Test
public void testParseTransformException() throws TransformerException {
    Builder builder = Mockito.mock(Builder.class);
    SOAPMessage message = Mockito.mock(SOAPMessage.class);
    doThrow(TransformerException.class).when(transformer).transform(any(Source.class), any(Result.class));
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message));
}
Also used : Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) SOAPMessage(javax.xml.soap.SOAPMessage) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) Test(org.junit.Test)

Example 2 with Builder

use of com.google.api.ads.common.lib.client.RequestInfo.Builder in project googleads-java-lib by googleads.

the class RequestInfoXPathSetTest method testParseWithNullMessage.

@Test
public void testParseWithNullMessage() {
    Builder builder = Mockito.mock(Builder.class);
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, null));
    // Message was null, so no methods should have been called on the builder.
    verifyNoMoreInteractions(builder);
}
Also used : Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) Test(org.junit.Test)

Example 3 with Builder

use of com.google.api.ads.common.lib.client.RequestInfo.Builder in project googleads-java-lib by googleads.

the class RequestInfoXPathSetTest method testParseWithNullTransformer.

@Test
public void testParseWithNullTransformer() {
    Builder builder = Mockito.mock(Builder.class);
    when(transformerSupplier.get()).thenReturn(null);
    SOAPMessage message = Mockito.mock(SOAPMessage.class);
    when(message.getSOAPPart()).thenReturn(Mockito.mock(SOAPPart.class));
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message));
    // Transformer was null, so no methods should have been called on the builder.
    verifyNoMoreInteractions(builder);
}
Also used : Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) SOAPPart(javax.xml.soap.SOAPPart) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 4 with Builder

use of com.google.api.ads.common.lib.client.RequestInfo.Builder in project googleads-java-lib by googleads.

the class RequestInfoXPathSetTest method testParseWithNullSoapPart.

@Test
public void testParseWithNullSoapPart() {
    Builder builder = Mockito.mock(Builder.class);
    SOAPMessage message = Mockito.mock(SOAPMessage.class);
    when(message.getSOAPPart()).thenReturn(null);
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message));
    // SOAPPart was null, so no methods should have been called on the builder.
    verifyNoMoreInteractions(builder);
}
Also used : Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 5 with Builder

use of com.google.api.ads.common.lib.client.RequestInfo.Builder in project googleads-java-lib by googleads.

the class RequestInfoXPathSetTest method testParseActualMessage.

@Test
public void testParseActualMessage() throws SOAPException, IOException, TransformerException {
    Builder builder = new Builder();
    SOAPMessage message = Mockito.mock(SOAPMessage.class);
    SOAPHeader header = Mockito.mock(SOAPHeader.class);
    SOAPPart soapPart = Mockito.mock(SOAPPart.class);
    when(message.getSOAPHeader()).thenReturn(header);
    when(message.getSOAPPart()).thenReturn(soapPart);
    final String payload = "<foo><bar>MyBar</bar></foo>";
    when(transformerSupplier.get()).thenReturn(transformer);
    doAnswer(invocation -> {
        StreamResult streamResult = (StreamResult) invocation.getArguments()[1];
        streamResult.getOutputStream().write(payload.getBytes(StandardCharsets.UTF_8));
        return null;
    }).when(transformer).transform(any(), any());
    assertSame("parseMessage should return the same builder passed in", builder, xPathSet.parseMessage(builder, message));
    RequestInfo requestInfo = builder.build();
    assertEquals("Payload doesn't match", payload, requestInfo.getPayload());
    assertEquals("Context name doesn't match", "bar", requestInfo.getContextName());
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) Builder(com.google.api.ads.common.lib.client.RequestInfo.Builder) SOAPPart(javax.xml.soap.SOAPPart) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) Test(org.junit.Test)

Aggregations

Builder (com.google.api.ads.common.lib.client.RequestInfo.Builder)5 Test (org.junit.Test)5 SOAPMessage (javax.xml.soap.SOAPMessage)4 SOAPPart (javax.xml.soap.SOAPPart)2 StreamResult (javax.xml.transform.stream.StreamResult)2 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 Result (javax.xml.transform.Result)1 Source (javax.xml.transform.Source)1