Merge "Bug 1446: Changed QNM to toString listener for debug output"
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / BaseConstraintsTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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 package org.opendaylight.yangtools.yang.model.util;
9
10 import com.google.common.base.Optional;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
13 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
14
15 import static org.junit.Assert.assertEquals;
16
17 public class BaseConstraintsTest {
18
19     @Test
20     public void canCreateConstraints() {
21         Number min = 5;
22         Number max = 99;
23         String description = "Any description";
24         String reference = "any_ref";
25         String reg_exp = "x|z";
26         Optional<String> desc = Optional.of(description);
27         Optional<String> ref = Optional.of(reference);
28
29         LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref);
30
31         assertEquals("LengthConstraints Get min", min, lengthCons.getMin());
32         assertEquals("LengthConstraints Get max", max, lengthCons.getMax());
33         assertEquals("LengthConstraints Get description", description, lengthCons.getDescription());
34         assertEquals("LengthConstraints Get reference", reference, lengthCons.getReference());
35
36         PatternConstraint patternCons = BaseConstraints.newPatternConstraint(reg_exp, desc, ref);
37
38         assertEquals("PatternConstraints Get regex", reg_exp, patternCons.getRegularExpression());
39         assertEquals("PatternConstraints Get description", description, patternCons.getDescription());
40         assertEquals("PatternConstraints Get reference", reference, patternCons.getReference());
41     }
42 }