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