2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.util;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import java.io.ByteArrayInputStream;
33 import org.junit.Test;
34 import org.onap.appc.util.StreamHelper;
36 public class StreamHelperTest {
38 private static final String text = "Filler text (also placeholder text or dummy text) is text that shares "
39 + "some characteristics of a real written text, but is random or otherwise generated. It may be used "
40 + "to display a sample of fonts, generate text for testing, or to spoof an e-mail spam filter. The "
41 + "process of using filler text is sometimes called greeking, although the text itself may be nonsense, "
42 + "or largely Latin, as in Lorem ipsum.\nASDF is the sequence of letters that appear on the first four "
43 + "keys on the home row of a QWERTY or QWERTZ keyboard. They are often used as a sample or test case "
44 + "or as random, meaningless nonsense. It is also a common learning tool for keyboard classes, since "
45 + "all four keys are located on Home row.\nETAOIN SHRDLU is the approximate order of frequency of the "
46 + "twelve most commonly used letters in the English language, best known as a nonsense phrase that "
47 + "sometimes appeared in print in the days of \"hot type\" publishing due to a custom of Linotype "
48 + "machine operators.\nLorem ipsum... is one of the most common filler texts, popular with "
49 + "typesetters and graphic designers. \"Li Europan lingues...\" is another similar example.\n"
50 + "Now is the time for all good men to come to the aid of the party\" is a phrase first proposed "
51 + "as a typing drill by instructor Charles E. Weller; its use is recounted in his book The Early "
52 + "History of the Typewriter, p. 21 (1918).[1] Frank E. McGurrin, an expert on the early Remington "
53 + "typewriter, used it in demonstrating his touch typing abilities in January 1889.[2] It has "
54 + "appeared in a number of typing books, often in the form \"Now is the time for all good men to "
55 + "come to the aid of their country.\"\nThe quick brown fox jumps over the lazy dog - A coherent, "
56 + "short phrase that uses every letter of the alphabet. See pangram for more examples.\nNew Petitions"
57 + " and Building Code - Many B movies of the 1940s, 50s, and 60s utilized the \"spinning newspaper\" "
58 + "effect to narrate important plot points that occurred offscreen. The effect necessitated the "
59 + "appearance of a realistic front page, which consisted of a main headline relevant to the plot, "
60 + "and several smaller headlines used as filler. A large number of these spinning newspapers "
61 + "included stories titled \"New Petitions Against Tax\" and \"Building Code Under Fire.\" These "
62 + "phrases have become running jokes among B movie fans, and particularly fans of Mystery "
63 + "Science Theater 3000. \nCharacter Generator Protocol - The Character Generator Protocol "
64 + "(CHARGEN) service is an Internet protocol intended for testing, debugging, and measurement "
65 + "purposes.\n!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefgh\n\""
66 + "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghi\n"
67 + "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghij\n"
68 + "$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijk\n";
71 public void should_return_empty_string_when_given_null_input_stream() {
72 assertNotNull(StreamHelper.getStringFromInputStream(null));
73 assertEquals("", StreamHelper.getStringFromInputStream(null));
77 public void should_return_empty_string_when_given_empty_byte_array() {
78 ByteArrayInputStream emptyInputStream = new ByteArrayInputStream(new byte[0]);
80 assertEquals("", StreamHelper.getStringFromInputStream(emptyInputStream));
84 public void should_return_string_when_given_byte_array() {
85 ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes());
87 assertEquals(text, StreamHelper.getStringFromInputStream(inputStream));