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=4295c29a22cea2f538d0006d94c70957163fabf9;hb=56978581354ce79ffadaa4544302e71c5169f37c;hpb=a57a5b4002790af8574db2b1d940106298bf18c3 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 4295c29a22..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,9 +13,12 @@ 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; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; @@ -18,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; @@ -31,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; @@ -52,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); @@ -138,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 @@ -149,14 +157,14 @@ public final class TestUtils { ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules)); prepareMocksForRestconf(modules, restconf); - restconf.createConfigurationData(schemaNodePath, compositeNode); + restconf.updateConfigurationData(schemaNodePath, compositeNode); } /** * 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); @@ -271,9 +279,39 @@ 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(); } + + public static String loadTextFile(String filePath) throws IOException { + FileReader fileReader = new FileReader(filePath); + BufferedReader bufReader = new BufferedReader(fileReader); + + String line = null; + StringBuilder result = new StringBuilder(); + while ((line = bufReader.readLine()) != null) { + result.append(line); + } + 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(); + } }