package org.ovirt.engine.api.restapi.types;

import org.ovirt.engine.api.model.NIC;
import org.ovirt.engine.api.model.Network;
import org.ovirt.engine.api.model.Networks;
import org.ovirt.engine.api.model.NicInterface;
import org.ovirt.engine.core.common.businessentities.VmNetworkInterface;

public class NicMapperTest extends AbstractInvertibleMappingTest<NIC, VmNetworkInterface, VmNetworkInterface> {

    protected NicMapperTest() {
        super(NIC.class, VmNetworkInterface.class, VmNetworkInterface.class);
    }

    @Override
    protected NIC postPopulate(NIC model) {
        model.setInterface(MappingTestHelper.shuffle(NicInterface.class).value());
        Network network = new Network();
        network.setName("rhel");
        Networks networks = new Networks();
        Network net = new Network();
        net.setName("rhel");
        model.getPortMirroring().setNetworks(networks);
        model.getPortMirroring().getNetworks().getNetworks().add(net);
        model.setNetwork(network);

        return model;
    }

    @Override
    protected void verify(NIC model, NIC transform) {
        assertNotNull(transform);
        assertEquals(model.getName(), transform.getName());
        assertEquals(model.getId(), transform.getId());
        assertNotNull(transform.getVm());
        assertEquals(model.getVm().getId(), transform.getVm().getId());
        assertNotNull(transform.getNetwork());
        assertEquals(model.getNetwork().getName(), transform.getNetwork().getName());
        assertNotNull(transform.getMac());
        assertEquals(model.getMac().getAddress(), transform.getMac().getAddress());
        assertEquals(model.getInterface(), transform.getInterface());

        assertEquals(model.isSetPortMirroring(), transform.isSetPortMirroring());
        if (model.isSetPortMirroring()) {
            assertEquals(model.getPortMirroring().isSetNetworks(), transform.getPortMirroring().isSetNetworks());
            if (model.getPortMirroring().isSetNetworks()) {
                assertEquals(model.getPortMirroring().getNetworks().isSetNetworks(),
                            transform.getPortMirroring().getNetworks().isSetNetworks());
                if (transform.getPortMirroring().getNetworks().isSetNetworks()) {
                    assertEquals(model.getPortMirroring().getNetworks().getNetworks().size(),
                                transform.getPortMirroring().getNetworks().getNetworks().size());
                    assertEquals(model.getPortMirroring().getNetworks().getNetworks().get(0).getName(),
                                transform.getPortMirroring().getNetworks().getNetworks().get(0).getName());
                }
            }
        }
    }
}

@@ -38,16 +38,39 @@
 types;%0A%0A
+import org.junit.Test;%0A
 import o
@@ -235,16 +235,65 @@
 erface;%0A
+import org.ovirt.engine.api.model.PortMirroring;%0A
 import o
@@ -356,16 +356,58 @@
 terface;
+%0Aimport org.ovirt.engine.core.compat.Guid;
 %0A%0Apublic
@@ -775,355 +775,8 @@
 ));%0A
-        Network network = new Network();%0A        network.setName(%22rhel%22);%0A        Networks networks = new Networks();%0A        Network net = new Network();%0A        net.setName(%22rhel%22);%0A        model.getPortMirroring().setNetworks(networks);%0A        model.getPortMirroring().getNetworks().getNetworks().add(net);%0A        model.setNetwork(network);%0A%0A
     
@@ -1466,48 +1466,52 @@
 ));%0A
-%0A
     
+%7D%0A%0A
     
-assertEquals(model.isSe
+@Test%0A    public void tes
 tPortMir
 rori
@@ -1510,50 +1510,25 @@
 tMir
-r
 o
+r
 ring
-(), transform.isSetPortMirror
+Mapp
 ing()
-);
+ %7B
 %0A   
@@ -1536,153 +1536,117 @@
     
-if (model.isSetPortMirroring()) %7B%0A            assertEquals(model.getPortMirroring().isSetNetworks(), transform.getPortMirroring().isSet
+NIC nic = new NIC();%0A        String netId = Guid.NewGuid().toString();%0A        Network network = new 
 Network
-s()
+(
 );%0A 
@@ -1656,133 +1656,62 @@
     
-    if (model.getPortMirroring().isSetNetworks()) %7B%0A                assertEquals(model.getPortMirroring().getNetworks().isSet
+network.setId(netId);%0A        Networks networks = new 
 Netw
@@ -1716,17 +1716,17 @@
 tworks()
-,
+;
 %0A       
@@ -1730,84 +1730,113 @@
     
-                    transform.getPortMirroring().getNetworks().isSetNetworks
+Network net = new Network();%0A        network.setId(netId);%0A        nic.setPortMirroring(new PortMirroring
 ());
@@ -1848,29 +1848,11 @@
     
-        if (transform
+nic
 .get
@@ -1859,33 +1859,33 @@
 PortMirroring().
-g
+s
 etNetworks().isS
@@ -1883,474 +1883,369 @@
 rks(
-).isSetNetworks()) %7B%0A                    assertEquals(model.getPortMirroring().getNetworks().getNetworks().size(),%0A                                transform.getPortMirroring().getNetworks().getNetworks().size());%0A                    assertEquals(model.getPortMirroring().getNetworks().getNetworks().get(0).getName(),%0A                                transform.getPortMirroring().getNetworks().getNetworks().get(0).getName());%0A                %7D%0A            %7D%0A        %7D
+networks);%0A        nic.getPortMirroring().getNetworks().getNetworks().add(net);%0A        nic.setNetwork(network);%0A        VmNetworkInterface entity = NicMapper.map(nic, null);%0A        assertTrue(entity.isPortMirroring());%0A%0A        nic.getPortMirroring().setNetworks(null);%0A        entity = NicMapper.map(nic, null);%0A        assertFalse(entity.isPortMirroring());
 %0A   

fix NicMappterTest build error