bbeb8c263bd01c00bf1c0285715df4f4a48071f8
[transportpce.git] / lighty / src / test / java / io / lighty / controllers / tpce / MaintTest.java
1 /*
2  * Copyright © 2020 Orange, 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 io.lighty.controllers.tpce;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.fail;
12
13 import java.io.File;
14
15 import org.eclipse.jetty.client.HttpClient;
16 import org.eclipse.jetty.client.api.ContentResponse;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class MaintTest {
24     private static final Logger LOG = LoggerFactory.getLogger(MaintTest.class);
25     private Main main = new Main();
26     private HttpClient client = new HttpClient();
27
28     @Before
29     @SuppressWarnings("checkstyle:Illegalcatch")
30     public void init() {
31         try {
32             client.start();
33         } catch (Exception e) {
34             LOG.error("An error occured during test init", e);
35             fail("cannot init test ");
36         }
37     }
38
39     @After
40     @SuppressWarnings("checkstyle:Illegalcatch")
41     public void stop() {
42         try {
43             main.shutdown();
44             client.stop();
45         } catch (Exception e) {
46             LOG.error("An error occured during test shutdown", e);
47         }
48     }
49
50     @Test
51     public void startNoConfigFileTest() throws Exception {
52         main.start(new String[0], true);
53         ContentResponse response = client.GET("http://localhost:8181/restconf/config/ietf-network:networks/network/openroadm-topology");
54         assertEquals("Response code should be 200", 200, response.getStatus());
55     }
56
57     @Test
58     public void startConfigFileTest() throws Exception {
59         File configFile = new File("src/test/resources/config.json");
60         String[] args = {configFile.getAbsolutePath()};
61         main.start(args, true);
62         ContentResponse response = client.GET("http://localhost:8888/restconfCustom/config/ietf-network:networks/network/openroadm-topology");
63         assertEquals("Response code should be 200", 200, response.getStatus());
64     }
65 }