2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.pcep.segment.routing02;
11 import com.google.common.collect.Lists;
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.Collections;
15 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.SrEroSubobject.Flags;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.pcinitiate.pcinitiate.message.requests.ero.subobject.subobject.type.SrEroTypeBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
27 public class SrEroUtilTest {
29 @Test(expected=UnsupportedOperationException.class)
30 public void testPrivateConstructor() throws Throwable {
31 final Constructor<SrEroUtil> c = SrEroUtil.class.getDeclaredConstructor();
32 c.setAccessible(true);
35 } catch (InvocationTargetException e) {
41 public void testIsSegmentRoutingPath() {
42 Assert.assertTrue(SrEroUtil.isSegmentRoutingPath(createEro(Lists.newArrayList(createSRSubobject()))));
43 Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(Collections.<Subobject>emptyList())));
44 Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(null)));
45 Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(Lists.newArrayList(createIpPrefixSubobject()))));
49 public void testValidateSrEroSubobjects() {
50 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject()))));
51 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Collections.<Subobject>emptyList())));
52 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(null)));
53 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, true)))));
54 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, false)))));
55 Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, false)))));
56 Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE, SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, true)))));
57 Assert.assertEquals(PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS,
58 SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createIpPrefixSubobject()))));
61 private Ero createEro(final List<Subobject> subobejcts) {
62 return new EroBuilder().setSubobject(subobejcts).build();
65 private Subobject createSRSubobject() {
66 final SubobjectBuilder builder = new SubobjectBuilder();
67 builder.setSubobjectType(new SrEroTypeBuilder().build());
68 return builder.build();
71 private Subobject createSRSubobject(final long sid, final boolean isM) {
72 final SubobjectBuilder builder = new SubobjectBuilder();
73 builder.setSubobjectType(new SrEroTypeBuilder().setFlags(new Flags(false, false, isM, false)).setSid(sid).build());
74 return builder.build();
77 private Subobject createIpPrefixSubobject() {
78 final SubobjectBuilder builder = new SubobjectBuilder();
79 builder.setSubobjectType(new IpPrefixCaseBuilder().build());
80 return builder.build();