<commit_before>/*
 * Copyright 2014-2015 <NAME> <<EMAIL>>
 *
 * Licensed 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 org.gaul.s3proxy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;

import java.io.InputStream;
import java.net.URI;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteSource;

import org.assertj.core.api.Fail;

import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobAccess;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.ContainerAccess;
import org.jclouds.blobstore.domain.MultipartPart;
import org.jclouds.blobstore.domain.MultipartUpload;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.CopyOptions;
import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.ContentMetadata;
import org.jclouds.io.ContentMetadataBuilder;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.rest.HttpClient;
import org.jclouds.s3.S3Client;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public final class S3ProxyTest {
    private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
    private static final Set<String> SWIFT_BLOBSTORES = ImmutableSet.of(
            "rackspace-cloudfiles-uk",
            "rackspace-cloudfiles-us",
            "openstack-swift"
    );

    private URI s3Endpoint;
    private S3Proxy s3Proxy;
    private BlobStoreContext context;
    private BlobStore blobStore;
    private String blobStoreType;
    private BlobStoreContext s3Context;
    private BlobStore s3BlobStore;
    private String containerName;

    @Before
    public void setUp() throws Exception {
        TestUtils.S3ProxyLaunchInfo info = TestUtils.startS3Proxy();
        s3Proxy = info.getS3Proxy();
        context = info.getBlobStore().getContext();
        blobStore = info.getBlobStore();
        blobStoreType = context.unwrap().getProviderMetadata().getId();
        s3Endpoint = info.getEndpoint();

        containerName = createRandomContainerName();
        blobStore.createContainerInLocation(null, containerName);

        Properties s3Properties = new Properties();
        s3Properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
        s3Context = ContextBuilder
                .newBuilder("s3")
                .credentials(info.getS3Identity(), info.getS3Credential())
                .endpoint(s3Endpoint.toString())
                .overrides(s3Properties)
                .build(BlobStoreContext.class);
        s3BlobStore = s3Context.getBlobStore();
    }

    @After
    public void tearDown() throws Exception {
        if (s3Proxy != null) {
            s3Proxy.stop();
        }
        if (s3Context != null) {
            s3Context.close();
        }
        if (context != null) {
            context.getBlobStore().deleteContainer(containerName);
            context.close();
        }
    }

    @Test
    public void testHttpClient() throws Exception {
        String blobName = "blob-name";
        Blob blob = blobStore.blobBuilder(blobName)
                .payload(BYTE_SOURCE)
                .contentLength(BYTE_SOURCE.size())
                .build();
        blobStore.putBlob(containerName, blob);

        if (blobStoreType.equals("azureblob")) {
            // Azure does not support public read objects
            blobStore.setContainerAccess(containerName,
                    ContainerAccess.PUBLIC_READ);
        } else {
            blobStore.setBlobAccess(containerName, blobName,
                    BlobAccess.PUBLIC_READ);
        }<commit_msg>Use container public-read for Swift test<commit_after>/*
 * Copyright 2014-2015 <NAME> <<EMAIL>>
 *
 * Licensed 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 org.gaul.s3proxy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;

import java.io.InputStream;
import java.net.URI;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteSource;

import org.assertj.core.api.Fail;

import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobAccess;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.ContainerAccess;
import org.jclouds.blobstore.domain.MultipartPart;
import org.jclouds.blobstore.domain.MultipartUpload;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.CopyOptions;
import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.ContentMetadata;
import org.jclouds.io.ContentMetadataBuilder;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.rest.HttpClient;
import org.jclouds.s3.S3Client;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public final class S3ProxyTest {
    private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
    private static final Set<String> SWIFT_BLOBSTORES = ImmutableSet.of(
            "rackspace-cloudfiles-uk",
            "rackspace-cloudfiles-us",
            "openstack-swift"
    );

    private URI s3Endpoint;
    private S3Proxy s3Proxy;
    private BlobStoreContext context;
    private BlobStore blobStore;
    private String blobStoreType;
    private BlobStoreContext s3Context;
    private BlobStore s3BlobStore;
    private String containerName;

    @Before
    public void setUp() throws Exception {
        TestUtils.S3ProxyLaunchInfo info = TestUtils.startS3Proxy();
        s3Proxy = info.getS3Proxy();
        context = info.getBlobStore().getContext();
        blobStore = info.getBlobStore();
        blobStoreType = context.unwrap().getProviderMetadata().getId();
        s3Endpoint = info.getEndpoint();

        containerName = createRandomContainerName();
        blobStore.createContainerInLocation(null, containerName);

        Properties s3Properties = new Properties();
        s3Properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
        s3Context = ContextBuilder
                .newBuilder("s3")
                .credentials(info.getS3Identity(), info.getS3Credential())
                .endpoint(s3Endpoint.toString())
                .overrides(s3Properties)
                .build(BlobStoreContext.class);
        s3BlobStore = s3Context.getBlobStore();
    }

    @After
    public void tearDown() throws Exception {
        if (s3Proxy != null) {
            s3Proxy.stop();
        }
        if (s3Context != null) {
            s3Context.close();
        }
        if (context != null) {
            context.getBlobStore().deleteContainer(containerName);
            context.close();
        }
    }

    @Test
    public void testHttpClient() throws Exception {
        String blobName = "blob-name";
        Blob blob = blobStore.blobBuilder(blobName)
                .payload(BYTE_SOURCE)
                .contentLength(BYTE_SOURCE.size())
                .build();
        blobStore.putBlob(containerName, blob);

        if (blobStoreType.equals("azureblob") ||
                SWIFT_BLOBSTORES.contains(blobStoreType)) {
            // Azure and Swift do not support blob access control
            blobStore.setContainerAccess(containerName,
                    ContainerAccess.PUBLIC_READ);
        } else {
            blobStore.setBlobAccess(containerName, blobName,
                    BlobAccess.PUBLIC_READ);
        }
{'fraction_non_alphanumeric': 0.09536159600997507, 'fraction_numerical': 0.008179551122194513, 'mean_word_length': 3.3030042918454936, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4547553', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2854, 'n_words': 630}