/** * Mule Constant Contact Connector * * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ package org.mule.modules; import org.junit.Test; import org.mule.modules.constantcontact.ConstantContactClient; import static org.junit.Assert.assertEquals; public class ResponseHelperTest { @Test public void testExtractEmail() throws Exception { String response = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" + " <link href=\"/ws/customers/joesflowers/settings/emailaddresses/1\" rel=\"edit\" />\n" + " <id>http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses/1</id>\n" + " <title type=\"text\">joesflowers@example.com</title>\n" + " <updated>2009-05-21T17:44:04.609Z</updated>\n" + " <author>\n" + " <name>Constant Contact</name>\n" + " </author>\n" + " <content type=\"application/vnd.ctct+xml\">\n" + " <Email xmlns=\"http://ws.constantcontact.com/ns/1.0/\" id=\"http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses/1\">\n" + " <EmailAddress>joesflowers@example.com</EmailAddress>\n" + " <Status>Verified</Status>\n" + " <VerifiedTime>2009-05-21T17:44:04.609Z</VerifiedTime>\n" + " </Email>\n" + " </content>\n" + " <source>\n" + " <id>http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses</id>\n" + " <title type=\"text\" />\n" + " <link href=\"http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses\" />\n" + " <link href=\"http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses\" rel=\"self\" />\n" + " <author>\n" + " <name>joesflowers</name>\n" + " </author>\n" + " <updated>2009-10-01T21:06:25.486Z</updated>\n" + " </source>\n" + "</entry>"; String emailEntry = new ConstantContactClient(null, null, null).extractEmail(response); String expected = "<Email xmlns=\"http://ws.constantcontact.com/ns/1.0/\" id=\"http://api.constantcontact.com/ws/customers/joesflowers/settings/emailaddresses/1\">" + "<EmailAddress>joesflowers@example.com</EmailAddress>" + "<Status>Verified</Status>" + "<VerifiedTime>2009-05-21T17:44:04.609Z</VerifiedTime>" + "</Email>".replaceAll("\n", "").replaceAll("\\s", ""); String actual = emailEntry.replaceAll("\n", "").replaceAll(">\\s+<", "><"); assertEquals(expected, actual); } }