org.jasig.portlet.blackboardvcportlet.dao.ws.impl.PresentationWSDaoImplTest.java Source code

Java tutorial

Introduction

Here is the source code for org.jasig.portlet.blackboardvcportlet.dao.ws.impl.PresentationWSDaoImplTest.java

Source

/**
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo licenses this file to you 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 the following location:
 *
 *   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 org.jasig.portlet.blackboardvcportlet.dao.ws.impl;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.jasig.portlet.blackboardvcportlet.dao.ws.SessionWSDao;
import org.jasig.portlet.blackboardvcportlet.data.ConferenceUser;
import org.jasig.portlet.blackboardvcportlet.service.SessionForm;
import org.jasig.portlet.blackboardvcportlet.service.util.SASWebServiceOperations;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.elluminate.sas.BlackboardPresentationResponseCollection;
import com.elluminate.sas.BlackboardSessionResponse;
import com.elluminate.sas.BlackboardSuccessResponse;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/test-applicationContext.xml")
public class PresentationWSDaoImplTest extends PresentationWSDaoImplTestBase {
    @Mock
    private SASWebServiceOperations sasWebServiceOperations;
    @Mock
    private BlackboardSessionResponse session;
    @Mock
    private SessionWSDao sessionDao;

    @Before
    public void before() throws Exception {
        MockitoAnnotations.initMocks(this);
        super.sessionDao = this.sessionDao;
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/ListSessionPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sessionDao.createSession(any(ConferenceUser.class), any(SessionForm.class))).thenReturn(session);
        dao.setSasWebServiceOperations(sasWebServiceOperations);
        super.before();
    }

    @Test
    public void uploadPresentationTest() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        super.uploadPresentationTest();
    }

    @Test
    public void linkPresentationToSessionTest() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/SetSessionPresentation"), any(Object.class)))
                        .thenReturn(getSuccessfulResponse());
        super.linkPresentationToSessionTest();
    }

    @Test
    public void getSessionPresentations() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/SetSessionPresentation"), any(Object.class)))
                        .thenReturn(getSuccessfulResponse());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/ListSessionPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        super.getSessionPresentations();
    }

    @Test
    public void getRepositoryPresentationsTest() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/ListRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());

        super.getRepositoryPresentationsTest();
    }

    @Test
    public void deletePresentation() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/RemoveRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSuccessfulResponse());
        super.deletePresentation();
    }

    @Test
    public void deleteSessionPresenation() throws Exception {
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/UploadRepositoryPresentation"), any(Object.class)))
                        .thenReturn(getSinglePresentation());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/SetSessionPresentation"), any(Object.class)))
                        .thenReturn(getSuccessfulResponse());
        when(sasWebServiceOperations.marshalSendAndReceiveToSAS(
                Matchers.contains("http://sas.elluminate.com/RemoveSessionPresentation"), any(Object.class)))
                        .thenReturn(getSuccessfulResponse());
        super.deleteSessionPresenation();
    }

    @SuppressWarnings("unchecked")
    private JAXBElement<BlackboardPresentationResponseCollection> getSinglePresentation() throws JAXBException {
        final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas");
        final Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<BlackboardPresentationResponseCollection> response = (JAXBElement<BlackboardPresentationResponseCollection>) unmarshaller
                .unmarshal(this.getClass()
                        .getResourceAsStream("/data/singleListRepositoryPresentationResponseCollection.xml"));

        return response;
    }

    private BlackboardSuccessResponse getSuccessfulResponse() {
        BlackboardSuccessResponse response = new BlackboardSuccessResponse();
        response.setSuccess(true);
        return response;
    }
}