Package com.consol.citrus.ws.validation

Source Code of com.consol.citrus.ws.validation.SimpleSoapAttachmentValidatorTest

/*
* Copyright 2006-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.consol.citrus.ws.validation;

import com.consol.citrus.exceptions.ValidationException;
import com.consol.citrus.ws.message.SoapAttachment;
import com.consol.citrus.ws.message.SoapMessage;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Collections;

/**
* @author Christoph Deppisch
*/
public class SimpleSoapAttachmentValidatorTest {
   
    @Test
    public void testSimpleValidation() throws IOException {
        SoapAttachment controlAttachment = new SoapAttachment();
        controlAttachment.setContentId("soapAttachmentId");
        controlAttachment.setContentType("text/plain");
        controlAttachment.setContent("This is a test!");

        SoapMessage testMessage = new SoapMessage("Some Payload")
                                    .addAttachment(controlAttachment);

        SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
        validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
    }
   
    @Test
    public void testSimpleValidationNoControlContentId() throws IOException {
        SoapAttachment receivedAttachment = new SoapAttachment();
        receivedAttachment.setContentId("soapAttachmentId");
        receivedAttachment.setContentType("text/plain");
        receivedAttachment.setContent("This is a test!");

        SoapMessage testMessage = new SoapMessage("Some Payload")
                                    .addAttachment(receivedAttachment);

        SoapAttachment controlAttachment = new SoapAttachment();
        controlAttachment.setContentType("text/plain");
        controlAttachment.setContent("This is a test!");
       
        SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
        validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
    }
   
    @Test(expectedExceptions = ValidationException.class)
    public void testSimpleValidationWrongContentId() throws IOException {
        SoapAttachment receivedAttachment = new SoapAttachment();
        receivedAttachment.setContentId("soapAttachmentId");
        receivedAttachment.setContentType("text/plain");
        receivedAttachment.setContent("This is a test!");

        SoapMessage testMessage = new SoapMessage("Some Payload")
                                    .addAttachment(receivedAttachment);

        SoapAttachment controlAttachment = new SoapAttachment();
        controlAttachment.setContentId("wrongAttachmentId");
        controlAttachment.setContentType("text/plain");
        controlAttachment.setContent("This is a test!");
       
        SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
        validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
    }
   
    @Test(expectedExceptions = IllegalArgumentException.class)
    public void testSimpleValidationWrongContent() throws IOException {
        SoapAttachment receivedAttachment = new SoapAttachment();
        receivedAttachment.setContentId("soapAttachmentId");
        receivedAttachment.setContentType("text/plain");
        receivedAttachment.setContent("This is a test!");

        SoapMessage testMessage = new SoapMessage("Some Payload")
                                    .addAttachment(receivedAttachment);

        SoapAttachment controlAttachment = new SoapAttachment();
        controlAttachment.setContentId("soapAttachmentId");
        controlAttachment.setContentType("text/plain");
        controlAttachment.setContent("This is not OK!");
       
        SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
        validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
    }
   
    @Test(expectedExceptions = IllegalArgumentException.class)
    public void testSimpleValidationWrongContentType() throws IOException {
        SoapAttachment receivedAttachment = new SoapAttachment();
        receivedAttachment.setContentId("soapAttachmentId");
        receivedAttachment.setContentType("text/plain");
        receivedAttachment.setContent("This is a test!");

        SoapMessage testMessage = new SoapMessage("Some Payload")
                                    .addAttachment(receivedAttachment);

        SoapAttachment controlAttachment = new SoapAttachment();
        controlAttachment.setContentId("soapAttachmentId");
        controlAttachment.setContentType("text/xml");
        controlAttachment.setContent("This is a test!");
       
        SimpleSoapAttachmentValidator validator = new SimpleSoapAttachmentValidator();
        validator.validateAttachment(testMessage, Collections.singletonList(controlAttachment));
    }
}
TOP

Related Classes of com.consol.citrus.ws.validation.SimpleSoapAttachmentValidatorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.