Search in sources :

Example 1 with TemplateResponse

use of com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillRESTRequestTest method testTemplateResponseConversion.

@Test
public void testTemplateResponseConversion() throws IOException {
    this.initRequestWithActualMapper();
    StringWriter sw = new StringWriter();
    IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("templates/templateResponse.txt"), sw);
    TemplateResponse response = (TemplateResponse) this.request.convertResponseData(sw.toString(), TemplateResponse.class);
    assertEquals("example name", response.getName());
    assertEquals("example code", response.getCode());
    assertEquals("example created_at", response.getCreated_at());
    assertEquals("example updated_at", response.getUpdated_at());
}
Also used : StringWriter(java.io.StringWriter) TemplateResponse(com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse) Test(org.junit.Test)

Example 2 with TemplateResponse

use of com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillTemplatesRequest method getTemplates.

public TemplateListResponse getTemplates(BaseMandrillRequest listRequest) throws RequestFailedException {
    TemplateListResponse response = new TemplateListResponse();
    response.setList(((BaseMandrillAnonymousListResponse<TemplateResponse>) request.postRequest(listRequest, ServiceMethods.Templates.LIST, TemplateResponse.class, templatesListReference)).getList());
    return response;
}
Also used : TemplateListResponse(com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateListResponse) TemplateResponse(com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse)

Example 3 with TemplateResponse

use of com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillRESTRequestTest method testTemplateListResponseConversion.

@Test
public void testTemplateListResponseConversion() throws IOException {
    this.initRequestWithActualMapper();
    StringWriter sw = new StringWriter();
    IOUtils.copy(this.getClass().getClassLoader().getResourceAsStream("templates/templatesListResponse.txt"), sw);
    TypeReference templatesListReference = new TypeReference<List<TemplateResponse>>() {
    };
    BaseMandrillAnonymousListResponse<TemplateResponse> response = (BaseMandrillAnonymousListResponse<TemplateResponse>) this.request.convertAnonymousListResponseData(sw.toString(), TemplateResponse.class, templatesListReference);
    assertEquals(2, response.getList().size());
    TemplateResponse tr = response.getList().get(0);
    assertEquals("example name1", tr.getName());
    assertEquals("example code1", tr.getCode());
    assertEquals("example created_at1", tr.getCreated_at());
    assertEquals("example updated_at1", tr.getUpdated_at());
    tr = response.getList().get(1);
    assertEquals("example name11", tr.getName());
    assertEquals("example code11", tr.getCode());
    assertEquals("example created_at11", tr.getCreated_at());
    assertEquals("example updated_at11", tr.getUpdated_at());
}
Also used : BaseMandrillAnonymousListResponse(com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse) StringWriter(java.io.StringWriter) TemplateResponse(com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 4 with TemplateResponse

use of com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse in project Java-Mandrill-Wrapper by cribbstechnologies.

the class TemplatesTest method testUpdateTemplate.

@Test
public void testUpdateTemplate() {
    MandrillRequestWithCode request = new MandrillRequestWithCode();
    request.setName("template1");
    String newVal = "<html><body>Not template</body></html>";
    request.setCode(newVal);
    MandrillRequestWithName retrieve = new MandrillRequestWithName();
    retrieve.setName("template1");
    try {
        TemplateResponse response = templatesRequest.getTemplateInfo(retrieve);
        String oldVal = response.getCode();
        templatesRequest.updateTemplate(request);
        response = templatesRequest.getTemplateInfo(retrieve);
        assertFalse(oldVal.equals(newVal));
        assertEquals(newVal, response.getCode());
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MandrillRequestWithName(com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) TemplateResponse(com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse) MandrillRequestWithCode(com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode) Test(org.junit.Test)

Aggregations

TemplateResponse (com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateResponse)4 Test (org.junit.Test)3 StringWriter (java.io.StringWriter)2 RequestFailedException (com.cribbstechnologies.clients.mandrill.exception.RequestFailedException)1 MandrillRequestWithCode (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode)1 MandrillRequestWithName (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName)1 BaseMandrillAnonymousListResponse (com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse)1 TemplateListResponse (com.cribbstechnologies.clients.mandrill.model.response.templates.TemplateListResponse)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1