Best Citrus code snippet using com.consol.citrus.validation.builder.StaticMessageContentBuilder
Source:ReceiveSoapMessageTestRunnerTest.java
...25import com.consol.citrus.message.MessageType;26import com.consol.citrus.messaging.Consumer;27import com.consol.citrus.report.TestActionListeners;28import com.consol.citrus.testng.AbstractTestNGUnitTest;29import com.consol.citrus.validation.builder.StaticMessageContentBuilder;30import com.consol.citrus.validation.context.HeaderValidationContext;31import com.consol.citrus.validation.json.JsonMessageValidationContext;32import com.consol.citrus.validation.xml.XmlMessageValidationContext;33import com.consol.citrus.ws.actions.ReceiveSoapMessageAction;34import com.consol.citrus.ws.message.SoapAttachment;35import com.consol.citrus.ws.message.SoapMessage;36import com.consol.citrus.ws.server.WebServiceServer;37import org.mockito.Mockito;38import org.springframework.context.ApplicationContext;39import org.springframework.core.io.Resource;40import org.testng.Assert;41import org.testng.annotations.BeforeClass;42import org.testng.annotations.Test;43import java.io.ByteArrayInputStream;44import java.io.IOException;45import java.util.HashMap;46import static org.mockito.Mockito.*;47/**48 * @author Christoph Deppisch49 */50public class ReceiveSoapMessageTestRunnerTest extends AbstractTestNGUnitTest {51 52 private Consumer messageConsumer = Mockito.mock(Consumer.class);53 private EndpointConfiguration configuration = Mockito.mock(EndpointConfiguration.class);54 private WebServiceServer server = Mockito.mock(WebServiceServer.class);55 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);56 private Resource resource = Mockito.mock(Resource.class);57 58 private SoapAttachment testAttachment = new SoapAttachment();59 60 /**61 * Setup test attachment.62 */63 @BeforeClass64 public void setup() {65 testAttachment.setContentId("attachment01");66 testAttachment.setContent("This is an attachment");67 testAttachment.setContentType("text/plain");68 testAttachment.setCharsetName("UTF-8");69 }70 @Test71 public void testWebServiceServerReceive() {72 reset(server, messageConsumer, configuration);73 when(server.createConsumer()).thenReturn(messageConsumer);74 when(server.getEndpointConfiguration()).thenReturn(configuration);75 when(configuration.getTimeout()).thenReturn(100L);76 when(server.getActor()).thenReturn(null);77 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("Foo")78 .setHeader("operation","foo")79 .addAttachment(testAttachment));80 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {81 @Override82 public void execute() {83 soap(action -> action.server(server)84 .receive()85 .messageType(MessageType.PLAINTEXT)86 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))87 .attachment(testAttachment));88 }89 };90 TestCase test = builder.getTestCase();91 Assert.assertEquals(test.getActionCount(), 1);92 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);93 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);94 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());95 Assert.assertEquals(action.getName(), "receive");96 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());97 Assert.assertEquals(action.getEndpoint(), server);98 Assert.assertEquals(action.getValidationContexts().size(), 3);99 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);100 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);101 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);102 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);103 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "Foo");104 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));105 Assert.assertEquals(action.getAttachments().size(), 1L);106 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());107 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());108 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());109 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());110 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());111 }112 @Test113 public void testSoapAttachment() {114 reset(server, messageConsumer, configuration);115 when(server.createConsumer()).thenReturn(messageConsumer);116 when(server.getEndpointConfiguration()).thenReturn(configuration);117 when(configuration.getTimeout()).thenReturn(100L);118 when(server.getActor()).thenReturn(null);119 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")120 .setHeader("operation","foo")121 .addAttachment(testAttachment));122 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {123 @Override124 public void execute() {125 soap(action -> action.server(server)126 .receive()127 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>").setHeader("operation", "foo"))128 .attachment(testAttachment));129 }130 };131 TestCase test = builder.getTestCase();132 Assert.assertEquals(test.getActionCount(), 1);133 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);134 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);135 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());136 Assert.assertEquals(action.getName(), "receive");137 138 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());139 Assert.assertEquals(action.getEndpoint(), server);140 Assert.assertEquals(action.getValidationContexts().size(), 3);141 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);142 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);143 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);144 145 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);146 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");147 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));148 Assert.assertEquals(action.getAttachments().size(), 1L);149 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());150 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());151 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());152 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());153 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());154 }155 @Test156 public void testSoapAttachmentData() {157 reset(server, messageConsumer, configuration);158 when(server.createConsumer()).thenReturn(messageConsumer);159 when(server.getEndpointConfiguration()).thenReturn(configuration);160 when(configuration.getTimeout()).thenReturn(100L);161 when(server.getActor()).thenReturn(null);162 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")163 .setHeader("operation","foo")164 .addAttachment(testAttachment));165 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {166 @Override167 public void execute() {168 soap(action -> action.server(server)169 .receive()170 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")171 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent()));172 }173 };174 TestCase test = builder.getTestCase();175 Assert.assertEquals(test.getActionCount(), 1);176 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);177 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);178 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());179 Assert.assertEquals(action.getName(), "receive");180 181 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());182 Assert.assertEquals(action.getEndpoint(), server);183 Assert.assertEquals(action.getValidationContexts().size(), 3);184 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);185 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);186 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);187 188 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);189 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");190 Assert.assertEquals(action.getAttachments().size(), 1L);191 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());192 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());193 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());194 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());195 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());196 }197 @Test198 public void testSoapAttachmentResource() throws IOException {199 final Resource attachmentResource = Mockito.mock(Resource.class);200 reset(server, messageConsumer, configuration, resource, attachmentResource);201 when(server.createConsumer()).thenReturn(messageConsumer);202 when(server.getEndpointConfiguration()).thenReturn(configuration);203 when(configuration.getTimeout()).thenReturn(100L);204 when(server.getActor()).thenReturn(null);205 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")206 .setHeader("operation","foo")207 .addAttachment(testAttachment));208 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<TestRequest><Message>Hello World!</Message></TestRequest>".getBytes()));209 when(attachmentResource.getInputStream()).thenReturn(new ByteArrayInputStream("This is an attachment".getBytes()));210 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {211 @Override212 public void execute() {213 soap(action -> action.server(server)214 .receive()215 .payload(resource)216 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), attachmentResource));217 }218 };219 TestCase test = builder.getTestCase();220 Assert.assertEquals(test.getActionCount(), 1);221 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);222 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);223 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());224 Assert.assertEquals(action.getName(), "receive");225 226 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());227 Assert.assertEquals(action.getEndpoint(), server);228 Assert.assertEquals(action.getValidationContexts().size(), 3);229 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);230 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);231 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);232 233 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);234 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");235 236 Assert.assertEquals(action.getAttachments().get(0).getContent(), "This is an attachment");237 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());238 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());239 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());240 }241 @Test242 public void testMultipleSoapAttachmentData() {243 final SoapAttachment attachment1 = new SoapAttachment();244 attachment1.setContentId("attachment01");245 attachment1.setContent("This is an attachment");246 attachment1.setContentType("text/plain");247 attachment1.setCharsetName("UTF-8");248 final SoapAttachment attachment2 = new SoapAttachment();249 attachment2.setContentId("attachment02");250 attachment2.setContent("This is an attachment");251 attachment2.setContentType("text/plain");252 attachment2.setCharsetName("UTF-8");253 reset(server, messageConsumer, configuration);254 when(server.createConsumer()).thenReturn(messageConsumer);255 when(server.getEndpointConfiguration()).thenReturn(configuration);256 when(configuration.getTimeout()).thenReturn(100L);257 when(server.getActor()).thenReturn(null);258 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")259 .setHeader("operation","foo")260 .addAttachment(attachment1)261 .addAttachment(attachment2));262 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {263 @Override264 public void execute() {265 soap(action -> action.server(server)266 .receive()267 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")268 .attachment(attachment1.getContentId(), attachment1.getContentType(), attachment1.getContent())269 .attachment(attachment2.getContentId(), attachment2.getContentType(), attachment2.getContent()));270 }271 };272 TestCase test = builder.getTestCase();273 Assert.assertEquals(test.getActionCount(), 1);274 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);275 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);276 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());277 Assert.assertEquals(action.getName(), "receive");278 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());279 Assert.assertEquals(action.getEndpoint(), server);280 Assert.assertEquals(action.getValidationContexts().size(), 3);281 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);282 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);283 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);284 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);285 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");286 Assert.assertEquals(action.getAttachments().size(), 2L);287 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());288 Assert.assertEquals(action.getAttachments().get(0).getContent(), attachment1.getContent());289 Assert.assertEquals(action.getAttachments().get(0).getContentId(), attachment1.getContentId());290 Assert.assertEquals(action.getAttachments().get(0).getContentType(), attachment1.getContentType());291 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), attachment1.getCharsetName());292 Assert.assertNull(action.getAttachments().get(1).getContentResourcePath());293 Assert.assertEquals(action.getAttachments().get(1).getContent(), attachment2.getContent());294 Assert.assertEquals(action.getAttachments().get(1).getContentId(), attachment2.getContentId());295 Assert.assertEquals(action.getAttachments().get(1).getContentType(), attachment2.getContentType());296 Assert.assertEquals(action.getAttachments().get(1).getCharsetName(), attachment2.getCharsetName());297 }298 @Test299 public void testReceiveBuilderWithEndpointName() {...
Source:ReceiveSoapMessageTestDesignerTest.java
...23import com.consol.citrus.message.DefaultMessage;24import com.consol.citrus.message.MessageType;25import com.consol.citrus.report.TestActionListeners;26import com.consol.citrus.testng.AbstractTestNGUnitTest;27import com.consol.citrus.validation.builder.StaticMessageContentBuilder;28import com.consol.citrus.validation.context.HeaderValidationContext;29import com.consol.citrus.validation.json.JsonMessageValidationContext;30import com.consol.citrus.validation.xml.XmlMessageValidationContext;31import com.consol.citrus.ws.actions.ReceiveSoapMessageAction;32import com.consol.citrus.ws.message.SoapAttachment;33import com.consol.citrus.ws.server.WebServiceServer;34import org.mockito.Mockito;35import org.springframework.context.ApplicationContext;36import org.springframework.core.io.Resource;37import org.testng.Assert;38import org.testng.annotations.BeforeClass;39import org.testng.annotations.Test;40import java.io.ByteArrayInputStream;41import java.io.IOException;42import java.util.HashMap;43import static org.mockito.Mockito.reset;44import static org.mockito.Mockito.when;45/**46 * @author Christoph Deppisch47 */48public class ReceiveSoapMessageTestDesignerTest extends AbstractTestNGUnitTest {49 50 private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);51 private WebServiceServer server = Mockito.mock(WebServiceServer.class);52 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);53 private Resource resource = Mockito.mock(Resource.class);54 55 private SoapAttachment testAttachment = new SoapAttachment();56 57 /**58 * Setup test attachment.59 */60 @BeforeClass61 public void setup() {62 testAttachment.setContentId("attachment01");63 testAttachment.setContent("This is an attachment");64 testAttachment.setContentType("text/plain");65 testAttachment.setCharsetName("UTF-8");66 }67 @Test68 public void testWebServiceServerReceive() {69 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {70 @Override71 public void configure() {72 soap().server(server)73 .receive()74 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))75 .attachment(testAttachment);76 }77 };78 builder.configure();79 TestCase test = builder.getTestCase();80 Assert.assertEquals(test.getActionCount(), 1);81 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);82 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);83 ReceiveSoapMessageAction action = (ReceiveSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();84 Assert.assertEquals(action.getName(), "receive");85 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());86 Assert.assertEquals(action.getEndpoint(), server);87 Assert.assertEquals(action.getValidationContexts().size(), 3);88 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);89 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);90 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);91 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);92 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "Foo");93 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));94 Assert.assertEquals(action.getAttachments().size(), 1L);95 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());96 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());97 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());98 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());99 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());100 }101 @Test102 public void testSoapAttachment() {103 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {104 @Override105 public void configure() {106 soap().server(server)107 .receive()108 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))109 .attachment(testAttachment);110 }111 };112 builder.configure();113 TestCase test = builder.getTestCase();114 Assert.assertEquals(test.getActionCount(), 1);115 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);116 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);117 ReceiveSoapMessageAction action = (ReceiveSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();118 Assert.assertEquals(action.getName(), "receive");119 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());120 Assert.assertEquals(action.getEndpoint(), server);121 Assert.assertEquals(action.getValidationContexts().size(), 3);122 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);123 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);124 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);125 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);126 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "Foo");127 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));128 Assert.assertEquals(action.getAttachments().size(), 1L);129 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());130 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());131 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());132 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());133 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());134 }135 136 @Test137 public void testSoapAttachmentData() {138 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {139 @Override140 public void configure() {141 soap().server(server)142 .receive()143 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")144 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent());145 }146 };147 builder.configure();148 TestCase test = builder.getTestCase();149 Assert.assertEquals(test.getActionCount(), 1);150 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);151 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);152 153 ReceiveSoapMessageAction action = (ReceiveSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();154 Assert.assertEquals(action.getName(), "receive");155 156 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());157 Assert.assertEquals(action.getEndpoint(), server);158 Assert.assertEquals(action.getValidationContexts().size(), 3);159 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);160 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);161 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);162 163 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);164 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");165 Assert.assertEquals(action.getAttachments().size(), 1L);166 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());167 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());168 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());169 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());170 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());171 }172 @Test173 public void testSoapAttachmentResource() throws IOException {174 final Resource attachmentResource = Mockito.mock(Resource.class);175 176 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {177 @Override178 public void configure() {179 soap().server(server)180 .receive()181 .payload(resource)182 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), attachmentResource);183 }184 };185 186 reset(resource, attachmentResource);187 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("somePayloadData".getBytes()));188 when(attachmentResource.getInputStream()).thenReturn(new ByteArrayInputStream("someAttachmentData".getBytes()));189 builder.configure();190 TestCase test = builder.getTestCase();191 Assert.assertEquals(test.getActionCount(), 1);192 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);193 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);194 195 ReceiveSoapMessageAction action = (ReceiveSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();196 Assert.assertEquals(action.getName(), "receive");197 198 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());199 Assert.assertEquals(action.getEndpoint(), server);200 Assert.assertEquals(action.getValidationContexts().size(), 3);201 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);202 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);203 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);204 205 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);206 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "somePayloadData");207 208 Assert.assertEquals(action.getAttachments().get(0).getContent(), "someAttachmentData");209 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());210 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());211 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());212 }213 @Test214 public void testMultipleSoapAttachmentData() {215 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {216 @Override217 public void configure() {218 soap().server(server)219 .receive()220 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")221 .attachment(testAttachment.getContentId() + 1, testAttachment.getContentType(), testAttachment.getContent() + 1)222 .attachment(testAttachment.getContentId() + 2, testAttachment.getContentType(), testAttachment.getContent() + 2);223 }224 };225 builder.configure();226 TestCase test = builder.getTestCase();227 Assert.assertEquals(test.getActionCount(), 1);228 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);229 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);230 ReceiveSoapMessageAction action = (ReceiveSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();231 Assert.assertEquals(action.getName(), "receive");232 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());233 Assert.assertEquals(action.getEndpoint(), server);234 Assert.assertEquals(action.getValidationContexts().size(), 3);235 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);236 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);237 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);238 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);239 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");240 Assert.assertEquals(action.getAttachments().size(), 2L);241 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());242 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent() + 1);243 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId() + 1);244 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());245 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());246 Assert.assertNull(action.getAttachments().get(1).getContentResourcePath());247 Assert.assertEquals(action.getAttachments().get(1).getContent(), testAttachment.getContent() + 2);248 Assert.assertEquals(action.getAttachments().get(1).getContentId(), testAttachment.getContentId() + 2);249 Assert.assertEquals(action.getAttachments().get(1).getContentType(), testAttachment.getContentType());250 Assert.assertEquals(action.getAttachments().get(1).getCharsetName(), testAttachment.getCharsetName());251 }252 @Test253 public void testReceiveBuilderWithEndpointName() {...
Source:HttpServerResponseActionBuilder.java
...19import com.consol.citrus.dsl.actions.DelegatingTestAction;20import com.consol.citrus.endpoint.Endpoint;21import com.consol.citrus.http.message.*;22import com.consol.citrus.message.Message;23import com.consol.citrus.validation.builder.StaticMessageContentBuilder;24import org.springframework.http.HttpStatus;25import javax.servlet.http.Cookie;26/**27 * @author Christoph Deppisch28 * @since 2.429 */30public class HttpServerResponseActionBuilder extends SendMessageBuilder<SendMessageAction, HttpServerResponseActionBuilder> {31 /** Http message to send or receive */32 private HttpMessage httpMessage = new HttpMessage();33 /**34 * Default constructor using http client endpoint.35 * @param delegate36 * @param httpServer37 */38 public HttpServerResponseActionBuilder(DelegatingTestAction<TestAction> delegate, Endpoint httpServer) {39 super(delegate);40 delegate.setDelegate(new SendMessageAction());41 getAction().setEndpoint(httpServer);42 initMessage(httpMessage);43 }44 /**45 * Initialize message builder.46 * @param message47 */48 private void initMessage(HttpMessage message) {49 StaticMessageContentBuilder staticMessageContentBuilder = StaticMessageContentBuilder.withMessage(message);50 staticMessageContentBuilder.setMessageHeaders(message.getHeaders());51 getAction().setMessageBuilder(new HttpMessageContentBuilder(message, staticMessageContentBuilder));52 }53 @Override54 protected void setPayload(String payload) {55 httpMessage.setPayload(payload);56 }57 @Override58 public HttpServerResponseActionBuilder name(String name) {59 httpMessage.setName(name);60 return super.name(name);61 }62 63 /**...
StaticMessageContentBuilder
Using AI Code Generation
1package com.consol.citrus.validation.builder;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.context.ValidationContext;6import com.consol.citrus.validation.matcher.ValidationMatcherUtils;7import com.consol.citrus.validation.xml.XmlMessageValidationContext;8import com.consol.citrus.validation.xml.XmlMessageValidationContext.Builder;9import org.springframework.util.StringUtils;10import java.util.*;11public class StaticMessageContentBuilder implements MessageContentBuilder {12 private String payload;13 private String messageType = MessageType.PLAINTEXT.name();14 private Map<String, Object> headers = new HashMap<String, Object>();15 private Map<String, Object> variables = new HashMap<String, Object>();16 private Map<String, Object> messageElements = new HashMap<String, Object>();17 private Map<String, Object> messageNamespaces = new HashMap<String, Object>();18 private Map<String, Object> messageAttributes = new HashMap<String, Object>();19 private Map<String, Object> messageValidationMatchers = new HashMap<String, Object>();20 private String messageValidationContext = XmlMessageValidationContext.class.getName();21 private String messageValidationContextBuilder = XmlMessageValidationContext.Builder.class.getName();22 private ValidationContext validationContext;23 private Collection<String> validationMatcherNames = new ArrayList<String>();24 public StaticMessageContentBuilder() {25 }26 public StaticMessageContentBuilder(String payload) {27 this.payload = payload;28 }29 public Message buildMessageContent(TestContext context, String messageType) {30 Message message = new Message(payload, headers);31 message.setType(MessageType.valueOf(messageType));32 for (Map.Entry<String, Object> entry : variables.entrySet()) {33 message.getVariables().put(entry.getKey(), context.replaceDynamicContentInString(entry.getValue().toString()));34 }35 for (Map.Entry<String, Object> entry : messageElements.entrySet()) {36 message.getMessageElements().put(entry.getKey(), context.replaceDynamicContentInString(entry.getValue().toString()));37 }38 for (
StaticMessageContentBuilder
Using AI Code Generation
1package com.consol.citrus.validation.builder;2import com.consol.citrus.testng.AbstractTestNGUnitTest;3import org.testng.Assert;4import org.testng.annotations.Test;5public class StaticMessageContentBuilderTest extends AbstractTestNGUnitTest {6 public void testBuildMessageContent() {7 StaticMessageContentBuilder builder = new StaticMessageContentBuilder("Hello Citrus!");8 Assert.assertEquals(builder.buildMessageContent(context), "Hello Citrus!");9 }10}
StaticMessageContentBuilder
Using AI Code Generation
1import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTest;4import org.testng.annotations.Test;5public class 4 extends TestNGCitrusTest {6public void 4() {7TestRunner runner = this.getTestRunner();8runner.http(builder -> builder.client("httpClient")9.send()10.post("/4")11.header("Content-Type", "application/xml")12"</4>"));13runner.http(builder -> builder.client("httpClient")14.receive()15.response(HttpStatus.OK)16.messageType(MessageType.PLAINTEXT)17.payload("Hello World!"));18}19}20import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;21import com.consol.citrus.dsl.runner.TestRunner;22import com.consol.citrus.dsl.testng.TestNGCitrusTest;23import org.testng.annotations.Test;24public class 5 extends TestNGCitrusTest {25public void 5() {26TestRunner runner = this.getTestRunner();27runner.http(builder -> builder.client("httpClient")28.send()29.post("/5")30.header("Content-Type", "application/json")31.payload("{\"5\": {\"text\": \"Hello World!\"}}"));32runner.http(builder -> builder.client("httpClient")33.receive()34.response(HttpStatus.OK)35.messageType(MessageType.PLAINTEXT)36.payload("Hello World!"));37}38}39import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;40import com.consol.citrus.dsl.runner.TestRunner;41import com.consol.citrus.dsl.testng.TestNGCitrusTest;42import org.testng.annotations.Test;43public class 6 extends TestNGCitrusTest {44public void 6() {45TestRunner runner = this.getTestRunner();46runner.http(builder -> builder.client("httpClient")47.send()48.post("/6")49.header("Content-Type", "application/x-www-form-urlencoded")50.payload("6.text=Hello World!"));51runner.http(builder -> builder.client("httpClient")52.receive()53.response(HttpStatus.OK)54.messageType(MessageType.PLAINTEXT)55.payload("Hello World!
StaticMessageContentBuilder
Using AI Code Generation
1public class StaticMessageContentBuilderTest {2 public void testStaticMessageContentBuilder() {3 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");4 Assert.assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null).getMessage());5 }6}7public class StaticMessageContentBuilderTest {8 public void testStaticMessageContentBuilder() {9 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");10 Assert.assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null).getMessage());11 }12}13public class StaticMessageContentBuilderTest {14 public void testStaticMessageContentBuilder() {15 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");16 Assert.assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null).getMessage());17 }18}19public class StaticMessageContentBuilderTest {20 public void testStaticMessageContentBuilder() {21 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");22 Assert.assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null).getMessage());23 }24}25public class StaticMessageContentBuilderTest {26 public void testStaticMessageContentBuilder() {27 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");28 Assert.assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null).getMessage());29 }30}31public class StaticMessageContentBuilderTest {32 public void testStaticMessageContentBuilder() {33 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");
StaticMessageContentBuilder
Using AI Code Generation
1StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder();2<ns0:Message>Hello World!</ns0:Message></ns0:echoResponse>");3staticMessageContentBuilder.setMessageType(MessageType.XML.name());4staticMessageContentBuilder.setMessageName("echoResponse");5XmlMessageValidationContext xmlMessageValidationContext = new XmlMessageValidationContext();6XmlMessageValidator xmlMessageValidator = new XmlMessageValidator();7xmlMessageValidator.setValidationContext(xmlMessageValidationContext);8MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();9messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);10MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();11messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);12MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();13messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);14MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();15messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);16MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();17messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);18MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();19messageValidatorRegistry.setMessageValidator(MessageType.XML.name(), xmlMessageValidator);20MessageValidatorRegistry messageValidatorRegistry = new MessageValidatorRegistry();21messageValidatorRegistry.setMessageValidator(MessageType.XML.name
StaticMessageContentBuilder
Using AI Code Generation
1public void staticMessageContentBuilderTest() {2 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World");3 assertEquals("Hello World", staticMessageContentBuilder.buildMessageContent(null, null));4}5public void xpathMessageContentBuilderTest() {6 XpathMessageContentBuilder xpathMessageContentBuilder = new XpathMessageContentBuilder("/Envelope/Body/Response/Result");7 assertEquals("result", xpathMessageContentBuilder.buildMessageContent(null, null));8}9public void xpathPayloadVariableExtractorTest() {10 XpathPayloadVariableExtractor xpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();11 xpathPayloadVariableExtractor.setXpathExpressions(Arrays.asList("/Envelope/Body/Response/Result"));12 Map<String, Object> variables = new HashMap<>();13 xpathPayloadVariableExtractor.extractVariables(variables, new DefaultMessage("test"));14 assertEquals("test", variables.get("result"));15}16public void xpathPayloadVariableExtractorTest() {17 XpathPayloadVariableExtractor xpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();18 xpathPayloadVariableExtractor.setXpathExpressions(Arrays.asList("/Envelope/Body/Response/Result"));19 Map<String, Object> variables = new HashMap<>();20 xpathPayloadVariableExtractor.extractVariables(variables, new DefaultMessage("test"));21 assertEquals("test", variables.get("result"));22}23public void xpathPayloadVariableExtractorTest() {24 XpathPayloadVariableExtractor xpathPayloadVariableExtractor = new XpathPayloadVariableExtractor();25 xpathPayloadVariableExtractor.setXpathExpressions(Arrays.asList("/Envelope/Body/Response/Result"));26 Map<String, Object> variables = new HashMap<>();27 xpathPayloadVariableExtractor.extractVariables(variable
StaticMessageContentBuilder
Using AI Code Generation
1package com.consol.citrus;2import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;3import org.springframework.context.support.ClassPathXmlApplicationContext;4public class StaticMessageContentBuilderDemo {5 public static void main(String[] args) {6 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");7 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello World!");8 System.out.println(staticMessageContentBuilder.buildMessageContent(context, null, null));9 }10}11package com.consol.citrus;12import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;13import org.springframework.context.support.ClassPathXmlApplicationContext;14import java.util.HashMap;15import java.util.Map;16public class StaticMessageContentBuilderDemo {17 public static void main(String[] args) {18 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");19 Map<String, Object> variables = new HashMap<>();20 variables.put("name", "John");21 variables.put("age", 25);22 StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder("Hello ${name}, you are ${age} years old!");23 System.out.println(staticMessageContentBuilder.buildMessageContent(context, variables, null));24 }25}26package com.consol.citrus;27import com.consol.citrus.dsl.builder.StaticMessageContentBuilder;28import org.springframework.context.support.ClassPathXmlApplicationContext;29import java.util.HashMap;30import java.util.Map;31public class StaticMessageContentBuilderDemo {32 public static void main(String[] args) {33 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
StaticMessageContentBuilder
Using AI Code Generation
1public class StaticMessageContentBuilderTest {2 public static void main(String[] args) {3 StaticMessageContentBuilder builder = new StaticMessageContentBuilder();4 builder.setMessageContent("<testMessage><text>Hello World!</text></testMessage>");5 System.out.println(builder.buildMessageContent());6 }7}
StaticMessageContentBuilder
Using AI Code Generation
1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.builder.StaticMessageContentBuilder;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import org.springframework.core.io.ClassPathResource;8import org.testng.annotations.Test;9import org.testng.anno
StaticMessageContentBuilder
Using AI Code Generation
1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.validation.builder.StaticMessageContentBuilder;6import org.junit.Test;7public class StaticMessageContentBuilderTest extends JUnit4CitrusTestDesigner {8public void staticMessageContentBuilderTest() {9StaticMessageContentBuilder staticMessageContentBuilder = new StaticMessageContentBuilder();10staticMessageContentBuilder.setMessageContent("Hello World!");11String messageContent = staticMessageContentBuilder.buildMessageContent(context, MessageType.PLAINTEXT.name());12validateMessage(messageContent, "Hello World!");13}14}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!