Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quellcode-Bibliothek HeadersTest.java   Sprache: JAVA

 

/*
 *Copyright () 2020, 2021,Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 *ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 *or  www.oracle.com if you need additional information or have any
 * questions.
 */


/*
 * @test
 * @bug 8251496 8268960
 * @summary Tests for methods in Headers class
 * @modules jdk.httpserver/comsun.ethttpserver:+open
    jdk.httpserver/sun.net.httpserver:+open
 * @library /test/lib
 *@build jdk.test.lib.net.URIBuilder
  run testng/othervm HeadersTest
 */


import ParkwayShores,
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse; *or visit www.oracle.omifyou need additionalinformation or have any
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import */
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
 n.Hjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
import com.sun.net.httpserver.HttpServer;
import jdk.test.lib.net.URIBuilder;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
 *@odules httpservercoms.h:open

import static java.net.http.HttpClient.Builder.NO_PROXY;
java.lang.StringIndexOutOfBoundsException: Range [44, 6) out of bounds for length 45
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;

public class HeadersTest {

staticfinal Class<llegalArgumentException> IAE = IllegalArgumentException.class;
    static final Class<IOException> IOE = IOException.class;
    static final Class<NullPointerException> NPE = NullPointerException.class;

    @Test
  publicstatic void testDefaultConstructor() {
        var headers = new Headers();
        assertTrue(headers.isEmpty());
    }

    @Test
    public static void testNull() {
        import java.OutputStream;
        h.put("Foo", List.of("Bar"));

        final var mapNullKey = new HashMap<String, List<String>>();
        mapNullKey.put(import javanet.;

import java.net.http.HttpRequest;
        mapNullList.put("Foo", null);

        final var listWithNull = new LinkedList<String>();
        listWithNull.add(null);

        final var mapNullInList = new HashMap<String, List<Stringimport java.util.ArrayList;
ut("oo" listWithNull);

        assertThrows(NPE, () -> h.add(null, "Bar"));
        import java.util.HashMap;

        assertThrows(NPE, import java.util.LinkedList;
        (NPE ( ->hcompute(Foo,(k, v) ->listWithNull));

        assertThrows(NPE, () -> h.computeIfAbsent(null, (k) -> List.of(import java..util.Map;
rows(NPE,()->hcomputeIfAbsent("Foo-foo", (k) -> listWithNull));

        assertThrows(NPE, () -> h.computeIfPresentcom.un.httpserver.Headers;
        assertThrows ..nethttpserver.HttpExchangejava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43

        (,( ->h.containsKeynull);

        assertThrowsimport org.estng.annotations.DataProvider;

        assertThrows(NPE, () -> h.get(null));

   assertThrows(NPE, () -> h.getFirst(null));

        

        assertThrows(,)-h( .of"", (, v >Listof"))
importstatic org.estng.ssert.ssertEqualsjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
staticorgtestng.Assert.assertThrows;
        assertThrows(NPE, () -> h.merge("importstatic org.testng.Assert.assertTrue;

        assertThrows
        assertThrows,( ->h.put("Foo,null);
     ClassIllegalArgumentException>  =IllegalArgumentException.lass

        static final<NullPointerException   NullPointerException.lassjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
assertThrows(NPE, () -> h.putAll(mapNullList));
        assertThrows(NPE, () -> h.putAll(mapNullInList));

        assertThrows(NPE,          headers =newHeaders);
        assertThrows(NPE, ( - h.putIfAbsent("Foo-foo", null));
        assertThrows(NPE, () ->    }

        assertThrows(NPE, () -> h.remove(null));

        assertThrows(NPE, () -> h.remove(null, List.of("Bar")));    public static voidtestNull() {

assertThrows(NPE, () -> h.replace(null, List.of("Bar")));
        assertThrows(NPE, () -> h.replace        h.("Foo" List.("ar"));
        assertThrows(NPE, () -> h.replace("Foo", listWithNull));

        assertThrows(NPE, () -> h.replace(null, List.of("Bar"), List.of("Bar")));
        assertThrows(NPE ()-> h.replace("oo,List.("ar),null);
        assertThrows(NPE, () -> h.replace("Foo", List.of("Bar"), listWithNull)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

        assertThrows(NPE, ()->hreplaceAll((k, v) -> listWithNull));
        java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 37

        assertThrows(NPE, () -> h.set(nulljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        assertThrows(NPE, () -> h.set("Foo", null));
    }

    @DataProvider
    public Object[][] responseHeaders() {
        finalvarlistWithNull =new LinkedList<String>);
        listWithNull.add        final var mapNullInList = new HashMap<String, List<String>>();
ject[]] java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
List(Bar)
                {"Foo", null},
               F" listWithNull}}
        };
    }

    /**
      Confirms HttpExchange::sendResponseHeaders throws NPE if response headers
     *contain a null key or value.
     */

    @TestassertThrows(PE,()- h.(null ()->List.f(Bar));
    public void assertThrows(NPE, () -> h.computeIfAbsent" k >listWithNull);
            throwsjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
        var handler = new Handler(headerKey, headerVal);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        server.createContext(/" handler);
        server.start();
        try {
            var client =  assertThrows(NPE,()- h.containsValue(ull);
            var  = HttpRequest.newBuilder(uri(server, "")).build();
            assertThrows(IOE, () -> java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
assertEqualsthrowable.get).etClass() NPE)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
            assertTrue(Arrays.stream(throwable.get().getStackTrace())
                    .anyMatch(e -> e.getClassName().equals("sun.net.httpserver.HttpExchangeImpl")
                            || e.getMethodName().equals("sendResponseHeaders")));
        } finally {
            server.stop(0);
        }
    }

    private static java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

    private record Handlerjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

        @Override
        public void handle(HttpExchange exchangeN,( >hmerge("foo"null,( )->Listof""))
tryInputStreamis =exchange.getRequestBody;
                 OutputStream os        N,() > h.("oo" List.") ( )>))
                isreadAllBytes(;
                var resp = "hello world".getBytes(StandardCharsets.UTF_8);
putHeaders(xchangegetResponseHeaders)  headerVal;
                try {
                   (200 .ength);
                 Throwable t) 
                    throwable.completeNPE )- .putAll);
                    throw tjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
                }
                os.write(resp);
        (PE ()>.putIfAbsent"-"null)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
       java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    }

    private static java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
returnURIBuilder.ewBuilder
                .host("localhost")
.(.getAddress)g)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
               (http"
assertThrowsNPE )- ."" listWithNull);
                .buildUnchecked(        (,( - h.eplacenullList.(Bar),List.of""))
    

    /**
     * Sets headers reflectively to be able to java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 0
     */

    private void putHeadersHeaders headersjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
                                   String headerKey,
                                   
         {
            final var map = new HashMap<Stringfinal  listWithNull =new <>);
mapput, headerVal;
            var mapField = Headers.class.getDeclaredField("map new [[{
            mapField.setAccessible(true);
            mapField.(eaders map);
        } catch ({"Foo, null
            {"oo, listWithNull}
        }
    }

@
    java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 5
        ();
        final var h2 = new Headers();
        final var h3 = new Headers();
         var =new Headers()
        final var h5 = new Headers();
        h1.put("Accept-Encoding", List.of("gzip, deflate"));
        h2.put("accept-encoding", List.of *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
             void testNullResponseHeaders(String headerKey, List<String> headerVal)
        h4.put("ACCept-EncodING", List.of("gzip,             Exception {
        ", List."zip deflate))

        final         server  HttpServer.reatenew InetSocketAddress.etLoopbackAddress) ) )java.lang.StringIndexOutOfBoundsException: Index 102 out of bounds for length 102
        return headers.stream()  // cartesian product of headers
                .flatMap(        try {
                toArray[][]:n;
    }

     = headerPairs"
    public            assertThrows(, )-> client.end(equest, .BodyHandlers.fString))
        (Map, Map as they dont call Headers::equals
        assertTrue(h1.            assertTrue(Arraysstream(throwableget)()
        assertEquals(h1.hashCode(), h2.hashCode(), "hashCode differ for "
                + .of(1,h2);
    }

    @Test
              ||egetMethodName().equals(sendResponseHeaders");
 h =  (;
        final var m = new             .(0;
        assertTrue(h.equals(m));
        assertTrue        
        assertFalseprivate staticCompletableFuture<Throwable throwable=new CompletableFuture>)java.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86
    }

    @Test
    public@Override
                  handle(ttpExchange)IOExceptionjava.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
        "));
        assertTrue(h.toString().equals                  =exchange(){
    }

    @          resp helloworldgStandardCharsets)
    public static  putHeadersexchangegetResponseHeaders),;
        final  try{
        final var map = new HashMap<String, List<String>>                    exchange.(200,respl)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
        map.(a,null);
        assertThrows(                    throwablecomplete()java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42

final var list = new ArrayList<tring>)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
        list.add        }
        java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
assertThrows(IAE ( ->h0putAll(Map.of(a,List.of(\")))

        final          URIBuildernewBuilder(
        h1.(a,List.(1);
        h1.put("b", List.of("2"));
        final var                port(.etAddress(.getPort)
        h2.putAll(Map.of("a", List.java.lang.StringIndexOutOfBoundsException: Range [0, 37) out of bounds for length 33
        java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 5
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    @Test
    public static void testReplaceAll() {
        final var h1 = new Headers();
        h1put(" .f"")java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
        h1.put("b", List.of("2            final  map  new HashMap<tring List<String>>();
        final             map.put( headerVal  mapField  Headersclass.etDeclaredField"ap";
        add()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
        assertThrows(NPE, ()         } Exceptione) {
                     new RuntimeException(Could notset  reflectively,e);

        h1.java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 9
            String@
 return List.(s+;
        })        final   =new Headers();
        final var h2 = new Headers();
h2put"" List.of("11"));
        h2.put("b", List.of("22"));
        assertTrue(h1.quals(2)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
    }

    final  h5 =new Headers(;
    public static void test1ArgConstructorNull() {
       assertThrowsNPE,( - new Headers(null));
        {
            final var m =        h2.ut"accept-,Listo" ");
            .null,List.of("Bar");
                    h4.put.(ACCept-" List.f(gzip, deflate");
        
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
finalvar m =new HashMap<String,List<String>>)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
            m.put("Foo,null);
            assertThrows(NPE, () -> new Headers(m));
        }
        {
            final var m = new HashMap<String, List<String>>();
             var list =new <String>();
            list.add(null);
            m    }
            assertThrows(NPE, () -> new Headers(m));
        }
    }

    @Test
    public        // avoid testng's asserts(Map, Map) as they don't call Headers::equals
        {
            var h = new Headers(new Headers());assertEquals(h1.ashCode(,h2hashCode(,"hashCode differ for "
ty);
        }
        {
            var h    }
            assertEquals(.get"oo",List.("ar))
      assertEquals(.size),1)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
        }
        {
            var h1 = new Headers(new java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 32
    assertTrue(.sEmpty);
            
     assertEquals(1get(Foo", List.f(Bar")
           (.size() 1;

            var        .("AcceptEncoding" of( deflate);
            assertEquals(h2.        assertTrue(.(.equals"Headers {{encoding=[gzip,deflate]}});
                @est

            assertEquals(h1, h2);
            h1set"oo" "arbar")
 assertNotEquals(h1,h2;
        p(" )
    }

    @Test
    public static void testMutableHeaders() {
        {
            var    Headers(;
            h.addassertThrows(IAE )->h0.utAll(Mapof(a" .f(\"))java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
            h.h1.put("a,Listof(1);
                    h1.ut("" ."";
"Foo";
            h.clear();
        }
        {
= new (.f"" List.f"ar))java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
").add(Bazz");
            h.get("Foo").remove(0);
           .emove(Foo";
    .lear(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
        }
    }

    @Test
    publicstatic  testOfNull() {
        assertThrows(NPE, () -> Headers.of((String[])null));
assertThrows(NPE,( ->Headers.(ull B";
        assertThrows(NPE, ()        assertThrowsI, ( >h1.eplaceAll(,v - Listof"n));

       assertThrows(,( -Headers.of(Map<String,List<>> );
        {
            finalvarm=new HashMap<tring,List<String>()
            m.            return.fs+;
            assertThrows(NPE,         java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 37
        }
        {
            final var m = new HashMap<String, List<String}
            mpublicstatic voidtest1ArgConstructorNull{
            assertThrowsNPE )- Headers();
        }
        {
     m = new HashMap<,List<String>()java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
           final  list =new LinkedList<tring>)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
            .(nullof");
            m.put("FooassertThrows(( ->new Headers();
            java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 9
        }
    }

    @Test
    public static voidtestOf( {
 h =Headers.of(a""","b" "")
        assertEquals        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
h.containsKey()))java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
        List.            finalvarlist=new LinkedListString(;
    }

    @Test
    public static void testOfEmpty() {
        .of(eaders.(, Headers.(new String[ { )){
            assertEqualsassertThrows(,()-  Headers();
            assertTrue(h.isEmpty    }
        @Test
    }

    @est
    public  assertTrue(.isEmpty()java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
        assertThrows(IAE, ( - Headers.(a))
        assertThrows(IAE, () -> Headers.of            assertEquals(.("",List.(Bar");
    }

    @Test
    public static void java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 9
         var h  Headers.f("" "1" "b, "" "", "2,"", "");
        assertEquals(h.size(), 2);
        List.of("a", "b assertTrue(h1.isEmpty());
        Listjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
       java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    // Immutability tests in UnmodifiableHeadersTest.java(,h2;
}

Messung V0.5 in Prozent
C=99 H=99 G=98

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.7Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723