/*
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * 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 org.jitsi.videobridge;

import net.java.sip.communicator.impl.protocol.jabber.extensions.colibri.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.*;
import org.jivesoftware.smack.packet.*;
import org.junit.*;
import org.junit.runner.*;
import org.junit.runners.*;

import static org.junit.Assert.*;

/**
 * Tests videobridge on conferences with raw UDP channels.
 *
 * @author Johannes Singler
 */
@RunWith(JUnit4.class)
public class RawUdpConferenceTest
{
    /**
     * Tested <tt>Videobridge</tt> instance.
     */
    private static Videobridge bridge;

    private static OSGiHandler osgiHandler = new OSGiHandler();

    /**
     * Initializes OSGi and the videobridge.
     */
    @BeforeClass
    public static void setUp()
        throws InterruptedException
    {
        osgiHandler.start();

        bridge = osgiHandler.getService(Videobridge.class);
    }

    /**
     * Shutdown OSGi and the videobridge.
     */
    @AfterClass
    public static void tearDown()
        throws InterruptedException
    {
        osgiHandler.stop();
    }

    /**
     * Tests when requesting a raw UDP channel, we do not get candidates with
     * 127.0.0.1 IPs.
     *
     * Test fails only if the machine has only a loopback interface, which is
     * very unlikely.
     */
    @Test
    public void testNo_127_0_0_0_CandidateIps()
        throws Exception
    {
        String focusJid = "focusJid";

        ColibriConferenceIQ confIq
            = ColibriUtilities.createConferenceIq(focusJid);
        confIq.getContents().get(0).getChannel(0).
                setTransport(new RawUdpTransportPacketExtension());

        IQ respIq = bridge.handleColibriConferenceIQ(confIq);

        assertTrue(respIq instanceof ColibriConferenceIQ);
        ColibriConferenceIQ respConfIq = (ColibriConferenceIQ) respIq;

        for (CandidatePacketExtension candidate :
                respConfIq.getContents().get(0).getChannel(0).
                        getTransport().getCandidateList())
        {
            assertNotEquals("127.0.0.1", candidate.getAttribute("ip"));
        }
    }
}

@@ -2716,11 +2716,928 @@
  %7D%0A    %7D
+%0A%0A    /**%0A     * Tests requesting a raw UDP channel with RTP level relay type MIXER%0A     */%0A    @Test%0A    public void testMixerChannel()%0A            throws Exception%0A    %7B%0A        String focusJid = %22focusJid%22;%0A%0A        ColibriConferenceIQ confIq%0A                = ColibriUtilities.createConferenceIq(focusJid);%0A        ColibriConferenceIQ.Channel channel%0A                = confIq.getContents().get(0).getChannel(0);%0A        channel.setTransport(new RawUdpTransportPacketExtension());%0A        channel.setRTPLevelRelayType(RTPLevelRelayType.MIXER);%0A%0A        IQ respIq = bridge.handleColibriConferenceIQ(confIq);%0A%0A        assertTrue(respIq instanceof ColibriConferenceIQ);%0A        ColibriConferenceIQ respConfIq = (ColibriConferenceIQ) respIq;%0A%0A        assertEquals(RTPLevelRelayType.MIXER,%0A                        respConfIq.getContents().get(0).getChannel(0).%0A                            getRTPLevelRelayType());%0A    %7D
 %0A%7D%0A

Add failing test RawUdpConferenceTest.testMixerChannel.