Abort power setup if setting gainloss fails
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / constraints / PceConstraintsCalcTest.java
1 /*
2  * Copyright © 2020 Orange Labs, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.pce.constraints;
10
11 import static org.junit.jupiter.api.Assertions.assertThrows;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import java.util.NoSuchElementException;
15 import org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
20 import org.opendaylight.transportpce.pce.utils.PceTestData;
21 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
22 import org.opendaylight.transportpce.pce.utils.TransactionUtils;
23 import org.opendaylight.transportpce.test.AbstractTest;
24
25 public class PceConstraintsCalcTest extends AbstractTest {
26     private static NetworkTransactionService networkTransactionService = null;
27     private DataBroker dataBroker = getDataBroker();
28
29     //TODO: review this test class. May be miss few assert.
30     @BeforeEach
31     void setup() throws Exception {
32         // networkTransactionService = Mockito.mock(NetworkTransactionService.class);
33         PceTestUtils.writeNetworkIntoDataStore(dataBroker, getDataStoreContextUtil(),
34                 TransactionUtils.getNetworkForSpanLoss());
35         networkTransactionService = new NetworkTransactionImpl(dataBroker);
36     }
37
38     @Test
39     void testNoHardOrSoftConstrainsExists() {
40         PceTestData.getPCE_test2_request_54().getSoftConstraints();
41         new PceConstraintsCalc(PceTestData.getEmptyPCERequest(), networkTransactionService);
42     }
43
44     @Test()
45     void testHardConstrainsExists() {
46         new PceConstraintsCalc(
47             PceTestData.getPCE_simpletopology_test1_requestSetHardAndSoftConstrains(),
48             networkTransactionService);
49     }
50
51     @Test()
52     void testHardConstrainsExists1() {
53         new PceConstraintsCalc(
54             PceTestData.getPathComputationRequestInputWithCoRoutingOrGeneral(),
55             networkTransactionService);
56     }
57
58     @Test
59     void testSoftConstrainsExists() {
60         new PceConstraintsCalc(PceTestData.getPCERequest(), networkTransactionService);
61     }
62
63     //TODO: See if this test is relevant.
64     @Test
65     void testHardConstrainsExists2() {
66         Exception exception = assertThrows(NoSuchElementException.class, () -> {
67             new PceConstraintsCalc(
68                     PceTestData.build_diversity_from_request(PceTestData.getPCERequest()),
69                     networkTransactionService);
70         });
71         assertTrue(exception.getMessage().contains("No value present"));
72     }
73
74     @Test()
75     void testHardConstrainsExists3() {
76         new PceConstraintsCalc(PceTestData.getEmptyPCERequestServiceNameWithRequestId(), networkTransactionService);
77     }
78
79     @Test()
80     void testHardConstrainsExists4() {
81         new PceConstraintsCalc(PceTestData.getPCE_test2_request_54(), networkTransactionService);
82     }
83 }