Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 3 | * |
| 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 S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame^] | 16 | package org.onosproject.pce.rest; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | |
| 22 | import java.io.IOException; |
| 23 | import java.io.InputStream; |
| 24 | |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.onosproject.codec.JsonCodec; |
| 28 | import org.onosproject.pce.pceservice.PcePath; |
| 29 | |
| 30 | import com.fasterxml.jackson.databind.JsonNode; |
| 31 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 32 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 33 | |
| 34 | /** |
| 35 | * PCE path codec unit tests. |
| 36 | */ |
| 37 | public 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 | } |