forked from apache/bookkeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZOOKEEPER-3205: Add test cases for jute
Adding some test cases for o.a.jute BinaryInputArchive . Issue ZOOKEEPER-3205 contains the patch as well. Author: Karthik K <karthiknetworklink@gmail.com> Reviewers: fangmin@apache.org, eolivelli@apache.org Closes apache#726 from akkumar/jutetest
- Loading branch information
Showing
7 changed files
with
440 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ nbdist/ | |
nb-configuration.xml | ||
nbactions.xml | ||
|
||
# vscode | ||
classes | ||
.vscode | ||
|
||
# Other | ||
*~ | ||
logs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
zookeeper-jute/src/test/java/org/apache/jute/TestCheckWriterReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.jute; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* TestOutputArchive creates an output archive from a given outputstream. | ||
*/ | ||
interface TestOutputArchive { | ||
|
||
OutputArchive getArchive(OutputStream os) throws IOException; | ||
} | ||
|
||
interface TestInputArchive { | ||
|
||
InputArchive getArchive(InputStream is) throws IOException; | ||
} | ||
|
||
class TestCheckWriterReader { | ||
|
||
static void checkWriterAndReader( | ||
TestOutputArchive output, TestInputArchive input, | ||
TestWriter writer, TestReader reader) { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try { | ||
OutputArchive oa = output.getArchive(baos); | ||
writer.write(oa); | ||
} catch (IOException e) { | ||
fail("Should not throw IOException while writing"); | ||
} | ||
InputStream is = new ByteArrayInputStream(baos.toByteArray()); | ||
try { | ||
InputArchive ia = input.getArchive(is); | ||
reader.read(ia); | ||
} catch (IOException e) { | ||
fail("Should not throw IOException while reading back"); | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
zookeeper-jute/src/test/java/org/apache/jute/TestReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.jute; | ||
|
||
import java.io.IOException; | ||
|
||
public interface TestReader { | ||
void read(InputArchive ia) throws IOException; | ||
} |
29 changes: 29 additions & 0 deletions
29
zookeeper-jute/src/test/java/org/apache/jute/TestWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.jute; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
public interface TestWriter { | ||
|
||
/** | ||
* Write to the given output archive. | ||
*/ | ||
void write(OutputArchive oa) throws IOException; | ||
} |
96 changes: 96 additions & 0 deletions
96
zookeeper-jute/src/test/java/org/apache/jute/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.jute; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.io.IOException; | ||
|
||
|
||
public class UtilsTest { | ||
|
||
void assertXMLString(String input) { | ||
String xmlString = Utils.toXMLString(input); | ||
String actual = Utils.fromXMLString(xmlString); | ||
Assert.assertEquals(input, actual); | ||
} | ||
|
||
@Test | ||
public void testXMLString() { | ||
assertXMLString("hello"); | ||
assertXMLString(",}%"); // special characters | ||
} | ||
|
||
void assertXMLBuffer(byte[] input) { | ||
String xmlString = Utils.toXMLBuffer(input); | ||
try { | ||
byte[] actual = Utils.fromXMLBuffer(xmlString); | ||
Assert.assertArrayEquals (input, actual); | ||
} catch (IOException ioex) { | ||
Assert.fail("Should not be throwing an IOException"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testXMLBuffer() { | ||
assertXMLBuffer("hello".getBytes()); | ||
} | ||
|
||
|
||
void assertCSVString(String input) { | ||
String csvString = Utils.toCSVString(input); | ||
try { | ||
String actual = Utils.fromCSVString(csvString); | ||
Assert.assertEquals(input, actual); | ||
} catch (IOException ioex) { | ||
Assert.fail("Should not be throwing an IOException"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCSVString() { | ||
assertCSVString("hello"); | ||
assertCSVString(",}%"); // special characters | ||
} | ||
|
||
@Test | ||
public void testFromCSVString() { | ||
try { | ||
Utils.fromCSVString("1"); // not starting with ' | ||
Assert.fail("Should have thrown an IOException"); | ||
} catch (IOException ioex) { | ||
|
||
} | ||
} | ||
|
||
void assertCSVBuffer(byte[] input) { | ||
String csvBuffer = Utils.toCSVBuffer(input); | ||
try { | ||
byte[] actual = Utils.fromCSVBuffer(csvBuffer); | ||
Assert.assertArrayEquals(input, actual); | ||
} catch (IOException ioex) { | ||
Assert.fail("Should not have thrown IOException during assertCSVBuffer"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCSVBuffer() { | ||
assertCSVBuffer("universe".getBytes()); | ||
} | ||
|
||
} |
Oops, something went wrong.