+ @Test
+ public void getIndexFromFrequencyTest() {
+ assertEquals("Index should be 693", 693, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(195.65625)));
+ assertEquals("Index should be 0", 0, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(191.325)));
+ assertEquals("Index should be 767", 767, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(196.11875)));
+ assertEquals("Index should be 8", 8, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(191.375)));
+ assertEquals("Index should be 15", 15, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(191.41875)));
+ assertEquals("Index should be 768", 768, GridUtils.getIndexFromFrequency(BigDecimal.valueOf(196.125)));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getIndexFromFrequencyExceptionTest() {
+ GridUtils.getIndexFromFrequency(BigDecimal.valueOf(196.13125));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getIndexFromFrequencyException2Test() {
+ GridUtils.getIndexFromFrequency(BigDecimal.valueOf(191.31875));
+ }
+
+ @Test
+ public void getWidthFromRateAndModulationFormatTest() {
+ assertEquals("Width should be 75", new FrequencyGHz(GridConstant.WIDTH_75),
+ GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_400,
+ ModulationFormat.DpQam16));
+ }
+
+ @Test
+ public void getWidthFromRateAndModulationFormatNotFoundTest() {
+ assertEquals("As not found width should be 40", new FrequencyGHz(GridConstant.WIDTH_40),
+ GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_100,
+ ModulationFormat.DpQam16));
+ }
+
+ @Test
+ public void getCentralFrequencyTest() {
+ assertEquals("Central frequency should be 191.350",
+ new FrequencyTHz(BigDecimal.valueOf(191.35).setScale(3)),
+ GridUtils.getCentralFrequency(BigDecimal.valueOf(191.325), BigDecimal.valueOf(191.375)));
+ }
+
+ @Test
+ public void getCentralFrequencyWithPrecisionTest() {
+ assertEquals("Central frequency should be 191.3500",
+ new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz(
+ BigDecimal.valueOf(191.35).setScale(4)),
+ GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.325),
+ BigDecimal.valueOf(191.375), 4));
+ }
+
+ @Test
+ public void getCentralFrequencyWithPrecisionAndRoundTest() {
+ assertEquals("Central frequency should be 191.3499",
+ new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz(
+ BigDecimal.valueOf(191.3499)),
+ 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());
+ }