blob: 022058d82dd18f6d804afee3bd33331484d4e3b6 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +05302 * Copyright 2016-present Open Networking Laboratory
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053016package org.onosproject.pce.rest;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053017
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21
22import java.io.IOException;
23import java.io.InputStream;
24
25import org.junit.Before;
26import org.junit.Test;
27import org.onosproject.codec.JsonCodec;
28import org.onosproject.pce.pceservice.PcePath;
29
30import com.fasterxml.jackson.databind.JsonNode;
31import com.fasterxml.jackson.databind.ObjectMapper;
32import com.fasterxml.jackson.databind.node.ObjectNode;
33
34/**
35 * PCE path codec unit tests.
36 */
37public class PcePathCodecTest {
38
39 MockPceCodecContext context;
40 JsonCodec<PcePath> pcePathCodec;
41 /**
42 * Sets up for each test. Creates a context and fetches the PCE path codec.
43 */
44 @Before
45 public void setUp() {
46 context = new MockPceCodecContext();
47 pcePathCodec = context.codec(PcePath.class);
48 assertThat(pcePathCodec, notNullValue());
49 }
50
51 /**
52 * Reads in a pce-path from the given resource and decodes it.
53 *
54 * @param resourceName resource to use to read the json for the pce-path
55 * @return decoded pce-path
56 * @throws IOException if processing the resource fails
57 */
58 private PcePath getPcePath(String resourceName) throws IOException {
59 InputStream jsonStream = PcePathCodecTest.class
60 .getResourceAsStream(resourceName);
61 ObjectMapper mapper = new ObjectMapper();
62 JsonNode json = mapper.readTree(jsonStream);
63 assertThat(json, notNullValue());
64 PcePath pcePath = pcePathCodec.decode((ObjectNode) json, context);
65 assertThat(pcePath, notNullValue());
66 return pcePath;
67 }
68
69 /**
70 * Checks that a simple pce-path is decoded properly.
71 *
72 * @throws IOException if the resource cannot be processed
73 */
74 @Test
75 public void codecPcePathTest() throws IOException {
76
77 PcePath pcePath = getPcePath("pcePath.json");
78
79 assertThat(pcePath, notNullValue());
80
81 assertThat(pcePath.source().toString(), is("11.0.0.1"));
82 assertThat(pcePath.destination(), is("11.0.0.2"));
83 assertThat(pcePath.lspType().toString(), is("SR_WITHOUT_SIGNALLING"));
84 //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint are ready
85 //assertThat(pcePath.costConstraint().toString(), is(2));
86 //assertThat(pcePath.bandwidthConstraint().toString(), is(200.0));
87 }
88}