3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 package org.opendaylight.controller.protobuff.messages;
14 import java.io.FileInputStream;
15 import java.io.FileOutputStream;
18 * @author: syedbahm Date: 7/31/14
20 public abstract class AbstractMessagesTest {
21 public final String VERSION_COMPATIBILTY_TEST_DATA_PATH = "." + File.separator + "src" + File.separator + "test"
22 + File.separator + "resources" + File.separator + "version-compatibility-serialized-data";
24 private File testDataFile;
26 protected AbstractMessagesTest() {
30 protected void init() {
31 file = new File(getTestFileName());
32 testDataFile = new File(VERSION_COMPATIBILTY_TEST_DATA_PATH + File.separator + getTestFileName() + "Data");
35 abstract public void verifySerialization() throws Exception;
37 protected void writeToFile(com.google.protobuf.GeneratedMessage.Builder<?> builder) throws Exception {
39 FileOutputStream output = new FileOutputStream(file);
40 builder.build().writeTo(output);
45 protected com.google.protobuf.GeneratedMessage readFromFile(com.google.protobuf.Parser<?> parser) throws Exception {
46 com.google.protobuf.GeneratedMessage message = (com.google.protobuf.GeneratedMessage) parser
47 .parseFrom(new FileInputStream(file));
50 * Note: we will delete only the test file -- comment below if you want
51 * to capture the version-compatibility-serialized-data test data
52 * file.The file will be generated at root of the
53 * sal-protocolbuffer-encoding and you need to move it to
54 * test/resources/version-compatbility-serialized-data folder renaming
55 * the file to include suffix <TestFileName>"Data"
61 protected com.google.protobuf.GeneratedMessage readFromTestDataFile(com.google.protobuf.Parser<?> parser)
63 return (com.google.protobuf.GeneratedMessage) parser.parseFrom(new FileInputStream(testDataFile));
66 public abstract String getTestFileName();