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