+/*
+ * 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;
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;
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;
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;
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);
}
/**
- *
- * Fill missing data (namespaces) and build correct data type in
- * {@code compositeNode} according to {@code dataSchemaNode}. The method
- * {@link RestconfImpl#createConfigurationData createConfigurationData} is
- * used because it contains calling of method {code normalizeNode}
+ *
+ * Fill missing data (namespaces) and build correct data type in {@code compositeNode} according to
+ * {@code dataSchemaNode}. The method {@link RestconfImpl#createConfigurationData createConfigurationData} is used
+ * because it contains calling of method {code normalizeNode}
*/
public static void normalizeCompositeNode(CompositeNode compositeNode, Set<Module> modules, String schemaNodePath) {
RestconfImpl restconf = RestconfImpl.getInstance();
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.
- *
+ * 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<Module> modules) {
assertNotNull("Modules can't be null.", modules);
ControllerContext.getInstance().setSchemas(loadSchemaContext(modules));
- messageBodyWriter.writeTo(new StructuredData(compositeNode, dataSchemaNode), null, null, null, null, null,
- byteArrayOS);
+ 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();
+ }
}