import static org.junit.Assert.fail;
import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
+import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.text.ParseException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.data.impl.TestUtils;
+import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StringPatternCheckingCodecTest {
private static final Logger LOG = LoggerFactory.getLogger(StringPatternCheckingCodecTest.class);
- private static final YangStatementSourceImpl TEST_MODULE = new YangStatementSourceImpl
- ("/string-pattern-checking-codec-test.yang", false);
@Test
- public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException {
- SchemaContext schemaContext = TestUtils.parseYangSources(TEST_MODULE);
+ public void testStringPatternCheckingCodec() throws ReactorException, URISyntaxException,
+ FileNotFoundException {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
+ "/string-pattern-checking-codec-test.yang");
assertNotNull(schemaContext);
- QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"),
- SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
-
- Module testModule = schemaContext.findModuleByName("string-pattern-checking-codec-test", null);
- assertNotNull(testModule);
+ final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"), null);
- ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.getDataChildByName(
+ final Module testModule = schemaContext.findModules("string-pattern-checking-codec-test").iterator().next();
+ final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.getDataChildByName(
QName.create(testModuleQName, "test-container"));
assertNotNull(testContainer);
- LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.getDataChildByName(
+ final LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.getDataChildByName(
QName.create(testModuleQName, "string-leaf-with-valid-pattern"));
assertNotNull(testLeaf);
- StringCodec<String> codec = getCodec(testLeaf.getType(), StringCodec.class);
+ final StringCodec<String> codec = getCodec(testLeaf.getType(), StringCodec.class);
assertNotNull(codec);
assertEquals("ABCD", codec.serialize("ABCD"));
assertEquals("ABCD", codec.deserialize("ABCD"));
try {
codec.deserialize("abcd");
fail("Exception should have been thrown.");
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
LOG.debug("IllegalArgumentException was thrown as expected: {}", ex);
- assertTrue(ex.getMessage().contains("is not valid regular expression. [abcd]"));
+ assertTrue(ex.getMessage().contains(
+ "Supplied value does not match the regular expression ^[A-Z]+$. [abcd]"));
}
}
}