brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alasdairhodge <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Performance improvements and othe...
Date Wed, 05 Aug 2015 12:00:41 GMT
Github user alasdairhodge commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/790#discussion_r36293578
  
    --- Diff: core/src/test/java/brooklyn/event/feed/http/HttpValueFunctionsTest.java ---
    @@ -0,0 +1,82 @@
    +/*
    + * 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
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * 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 brooklyn.event.feed.http;
    +
    +import static org.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertFalse;
    +import static org.testng.Assert.assertTrue;
    +
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import brooklyn.util.http.HttpToolResponse;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.gson.JsonElement;
    +import com.google.gson.JsonPrimitive;
    +
    +public class HttpValueFunctionsTest {
    +
    +    private int responseCode = 200;
    +    private long fullLatency = 1000;
    +    private String headerName = "my_header";
    +    private String body = "{mykey:myvalue}";
    +    private long now;
    +    private HttpToolResponse response;
    +    
    +    @BeforeMethod
    +    public void setUp() throws Exception {
    +        now = System.currentTimeMillis();
    +        response = new HttpToolResponse(responseCode, ImmutableMap.of(headerName, ImmutableList.of("myvalue")),
body.getBytes(), now-fullLatency, fullLatency/2, fullLatency);
    +    }
    +    
    +    @Test
    +    public void testResponseCode() throws Exception {
    +        assertEquals(HttpValueFunctions.responseCode().apply(response), Integer.valueOf(responseCode));
    +    }
    +
    +    @Test
    +    public void testContainsHeader() throws Exception {
    +        assertTrue(HttpValueFunctions.containsHeader(headerName).apply(response));
    +        assertFalse(HttpValueFunctions.containsHeader("wrong_header").apply(response));
    +    }
    +    
    +    @Test
    +    public void testStringContents() throws Exception {
    +        assertEquals(HttpValueFunctions.stringContentsFunction().apply(response), body);
    +    }
    +
    +    @Test
    +    public void testJsonContents() throws Exception {
    +        JsonElement json = HttpValueFunctions.jsonContents().apply(response);
    +        assertTrue(json.isJsonObject());
    +        assertEquals(json.getAsJsonObject().entrySet(), ImmutableMap.of("mykey", new
JsonPrimitive("myvalue")).entrySet());
    +    }
    +
    +    @Test
    +    public void testJsonContentsGettingElement() throws Exception {
    +        assertEquals(HttpValueFunctions.jsonContents("mykey", String.class).apply(response),
"myvalue");
    --- End diff --
    
    Add assert for absent value.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message