X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FTestUtils.java;h=449b79923edd40e0c21f922ba3ff6c271e45d3c5;hp=5ef66c3b257da4af2811a9e40b7c5d1908b4f474;hb=56978581354ce79ffadaa4544302e71c5169f37c;hpb=306f95ccf8d699e2eed111f193b2fc388fa03e70 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java index 5ef66c3b25..449b79923e 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertNotNull; @@ -6,6 +13,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.base.Preconditions; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -20,7 +28,8 @@ import java.sql.Date; import java.util.ArrayList; import java.util.List; import java.util.Set; - +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.ws.rs.WebApplicationException; import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; @@ -33,7 +42,6 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; - import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; @@ -54,8 +62,6 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.xml.sax.SAXException; -import com.google.common.base.Preconditions; - public final class TestUtils { private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class); @@ -140,7 +146,7 @@ public final class TestUtils { } /** - * + * * Fill missing data (namespaces) and build correct data type in * {@code compositeNode} according to {@code dataSchemaNode}. The method * {@link RestconfImpl#createConfigurationData createConfigurationData} is @@ -158,7 +164,7 @@ public final class TestUtils { * Searches module with name {@code searchedModuleName} in {@code modules}. * If module name isn't specified and module set has only one element then * this element is returned. - * + * */ public static Module resolveModule(String searchedModuleName, Set modules) { assertNotNull("Modules can't be null.", modules); @@ -273,7 +279,7 @@ public final class TestUtils { ControllerContext.getInstance().setSchemas(loadSchemaContext(modules)); - messageBodyWriter.writeTo(new StructuredData(compositeNode, dataSchemaNode), null, null, null, null, null, + messageBodyWriter.writeTo(new StructuredData(compositeNode, dataSchemaNode, null), null, null, null, null, null, byteArrayOS); return byteArrayOS.toString(); @@ -290,6 +296,22 @@ public final class TestUtils { } bufReader.close(); return result.toString(); + } + + private static Pattern patternForStringsSeparatedByWhiteChars(String ... substrings ) { + StringBuilder pattern = new StringBuilder(); + pattern.append(".*"); + for (String substring : substrings) { + pattern.append(substring); + pattern.append("\\s*"); + } + pattern.append(".*"); + return Pattern.compile(pattern.toString(), Pattern.DOTALL); + } + public static boolean containsStringData(String jsonOutput,String ...substrings ) { + Pattern pattern = patternForStringsSeparatedByWhiteChars(substrings); + Matcher matcher = pattern.matcher(jsonOutput); + return matcher.matches(); } }