Refactor to remove useless wavelength reference
[transportpce.git] / common / src / test / java / org / opendaylight / transportpce / common / fixedflex / GridUtilsTest.java
index 709ea040f4506b436ef56e6b264a2960e140b70b..08b549e0d00afbe799dc357873c20da54387f2af 100644 (file)
@@ -16,11 +16,14 @@ import java.util.Arrays;
 import java.util.Map;
 import org.junit.Test;
 import org.opendaylight.transportpce.common.ServiceRateConstant;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.ServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.ServicePathInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyGHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMaps;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public class GridUtilsTest {
 
@@ -114,4 +117,85 @@ public class GridUtilsTest {
                 GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.3244445),
                         BigDecimal.valueOf(191.3754457788), 4));
     }
+
+    @Test
+    public void initSpectrumInformationFromServicePathInputTest() {
+        ServicePathInput input = new ServicePathInputBuilder()
+                .setWaveNumber(Uint32.valueOf(1))
+                .setCenterFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyTHz(BigDecimal.valueOf(196.1)))
+                .setHigherSpectralSlotNumber(Uint32.valueOf(768))
+                .setLowerSpectralSlotNumber(Uint32.valueOf(761))
+                .setMaxFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyTHz(BigDecimal.valueOf(196.125)))
+                .setMinFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyTHz(BigDecimal.valueOf(196.075)))
+                .setWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyGHz(GridConstant.WIDTH_40))
+                .build();
+        SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
+        assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
+        assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
+        assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
+                spectrumInformation.getCenterFrequency());
+        assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
+        assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
+        assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
+                spectrumInformation.getMinFrequency());
+        assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
+                spectrumInformation.getMaxFrequency());
+    }
+
+    @Test
+    public void initSpectrumInformationFromServicePathInputNoCenterFreqTest() {
+        ServicePathInput input = new ServicePathInputBuilder()
+                .setWaveNumber(Uint32.valueOf(1))
+                .setHigherSpectralSlotNumber(Uint32.valueOf(768))
+                .setLowerSpectralSlotNumber(Uint32.valueOf(761))
+                .setMaxFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyTHz(BigDecimal.valueOf(196.125)))
+                .setMinFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyTHz(BigDecimal.valueOf(196.075)))
+                .setWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyGHz(GridConstant.WIDTH_40))
+                .build();
+        SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
+        assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
+        assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
+        assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
+                spectrumInformation.getCenterFrequency());
+        assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
+        assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
+        assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
+                spectrumInformation.getMinFrequency());
+        assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
+                spectrumInformation.getMaxFrequency());
+    }
+
+    @Test
+    public void initSpectrumInformationFromServicePathInputNoFreqTest() {
+        ServicePathInput input = new ServicePathInputBuilder()
+                .setWaveNumber(Uint32.valueOf(1))
+                .setHigherSpectralSlotNumber(Uint32.valueOf(768))
+                .setLowerSpectralSlotNumber(Uint32.valueOf(761))
+                .setWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
+                        .FrequencyGHz(GridConstant.WIDTH_40))
+                .build();
+        SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
+        assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
+        assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
+        assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
+                spectrumInformation.getCenterFrequency());
+        assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
+        assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
+        assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
+                spectrumInformation.getMinFrequency());
+        assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
+                spectrumInformation.getMaxFrequency());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void initSpectrumInformationFromServicePathInputNoSlotTest() {
+        GridUtils.initSpectrumInformationFromServicePathInput(new ServicePathInputBuilder().build());
+    }
 }