<commit_before>package com.airhacks.headlands.cache.boundary;

import com.airhacks.rulz.jaxrsclient.JAXRSClientProvider;
import java.util.List;
import java.util.Optional;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;

/**
 *
 * @author <EMAIL>
 */
public class CachesResourceIT {

    @Rule
    public JAXRSClientProvider tut = JAXRSClientProvider.buildWithURI("http://localhost:8080/headlands/resources/caches");

    @Test
    public void crudCaches() {
        final WebTarget target = this.tut.target();

        String cacheName = "cache-" + System.currentTimeMillis();
        Response response = target.request(MediaType.APPLICATION_JSON).get();
        assertThat(response.getStatus(), is(200));
        response = createCache(target, cacheName);
        assertThat(response.getStatus(), is(201));

        response = target.request(MediaType.APPLICATION_JSON).get();
        JsonArray cacheNames = response.readEntity(JsonArray.class);
        List<JsonObject> jsonStringList = cacheNames.getValuesAs(JsonObject.class);
        Optional<String> result = jsonStringList.stream().map(j -> j.getString("name")).
                filter(name -> name.equalsIgnoreCase(cacheName)).
                findAny();

        assertTrue(result.isPresent());

        response = target.path(cacheName).request(MediaType.APPLICATION_JSON).options();
        assertThat(response.getStatus(), is(200));

        JsonObject info = response.readEntity(JsonObject.class);
        System.out.println("info = " + info);
        assertNotNull(info);

        JsonObject configuration = Json.createObjectBuilder().build();
        response = target.path(cacheName).request().put(Entity.json(configuration));
        assertThat(response.getStatus(), is(200));
    }

    public static Response createCache(WebTarget target, String cacheName) {
        JsonObject configuration = Json.createObjectBuilder().build();
        return target.path(cacheName).request().put(Entity.json(configuration));

    }

}
<commit_msg>Cache expiration tested<commit_after>package com.airhacks.headlands.cache.boundary;

import com.airhacks.rulz.jaxrsclient.JAXRSClientProvider;
import java.util.List;
import java.util.Optional;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;

/**
 *
 * @author <EMAIL>
 */
public class CachesResourceIT {

    @Rule
    public JAXRSClientProvider tut = JAXRSClientProvider.buildWithURI("http://localhost:8080/headlands/resources/caches");

    static final String EXPIRY_FOR_ACCESS = "expiryForAccess";

    @Test
    public void crudCaches() {
        final WebTarget target = this.tut.target();

        String cacheName = "cache-" + System.currentTimeMillis();
        Response response = target.request(MediaType.APPLICATION_JSON).get();
        assertThat(response.getStatus(), is(200));
        response = createCache(target, cacheName);
        assertThat(response.getStatus(), is(201));

        response = target.request(MediaType.APPLICATION_JSON).get();
        JsonArray cacheNames = response.readEntity(JsonArray.class);
        List<JsonObject> jsonStringList = cacheNames.getValuesAs(JsonObject.class);
        Optional<String> result = jsonStringList.stream().map(j -> j.getString("name")).
                filter(name -> name.equalsIgnoreCase(cacheName)).
                findAny();

        assertTrue(result.isPresent());

        response = target.path(cacheName).request(MediaType.APPLICATION_JSON).options();
        assertThat(response.getStatus(), is(200));

        JsonObject info = response.readEntity(JsonObject.class);
        System.out.println("info = " + info);
        assertNotNull(info);
    }

    @Test
    public void validateExpiryForAccess() {
        final WebTarget target = this.tut.target();
        String cacheName = "cache-" + System.currentTimeMillis();
        long expectedExpiration = 4242;

        Response response = createCacheWithExpiration(target, expectedExpiration, cacheName);
        assertThat(response.getStatus(), is(201));

        response = target.path(cacheName).request(MediaType.APPLICATION_JSON).options();
        assertThat(response.getStatus(), is(200));

        JsonObject configuration = response.readEntity(JsonObject.class);
        assertNotNull(configuration);
        long actualExpiration = configuration.getJsonNumber(EXPIRY_FOR_ACCESS).longValue();
        assertThat(actualExpiration, is(expectedExpiration));

    }

    public static Response createCache(WebTarget target, String cacheName) {
        JsonObject configuration = Json.createObjectBuilder().build();
        return target.path(cacheName).request().put(Entity.json(configuration));

    }

    public static Response createCacheWithExpiration(WebTarget target, long expiryForAccess, String cacheName) {
        JsonObject configuration = Json.createObjectBuilder().add(EXPIRY_FOR_ACCESS, expiryForAccess).build();
        return target.path(cacheName).request().put(Entity.json(configuration));
    }

}

{'fraction_non_alphanumeric': 0.11982608695652174, 'fraction_numerical': 0.006782608695652174, 'mean_word_length': 3.894468085106383, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7325031', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1576, 'n_words': 280}