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 = "."
22 + File.separator + "src" + File.separator + "test" + File.separator
23 + "resources" + File.separator + "version-compatibility-serialized-data";
25 private File testDataFile;
27 protected AbstractMessagesTest() {
31 protected void init() {
32 file = new File(getTestFileName());
34 new File(VERSION_COMPATIBILTY_TEST_DATA_PATH + File.separator
35 + getTestFileName() + "Data");
40 abstract public void verifySerialization() throws Exception;
43 protected void writeToFile(
44 com.google.protobuf.GeneratedMessage.Builder<?> builder) throws Exception {
46 FileOutputStream output = new FileOutputStream(file);
47 builder.build().writeTo(output);
52 protected com.google.protobuf.GeneratedMessage readFromFile(
53 com.google.protobuf.Parser<?> parser) throws Exception {
54 com.google.protobuf.GeneratedMessage message =
55 (com.google.protobuf.GeneratedMessage) parser
56 .parseFrom(new FileInputStream(file));
58 /*Note: we will delete only the test file -- comment below if you want to capture the
59 version-compatibility-serialized-data test data file.The file will be generated at root of the
60 sal-protocolbuffer-encoding
61 and you need to move it to test/resources/version-compatbility-serialized-data folder renaming the file to include suffix <TestFileName>"Data"
67 protected com.google.protobuf.GeneratedMessage readFromTestDataFile(
68 com.google.protobuf.Parser<?> parser) throws Exception {
69 return (com.google.protobuf.GeneratedMessage) parser
70 .parseFrom(new FileInputStream(testDataFile));
74 public abstract String getTestFileName();