Repository: jclouds Updated Branches: refs/heads/master 8432c66b7 -> 34663f3c2
http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java new file mode 100644 index 0000000..3e92af5 --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java @@ -0,0 +1,129 @@ +/* + * 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 org.jclouds.openstack.swift.v1.features; + +import static java.lang.String.format; +import static org.jclouds.io.Payloads.newByteSourcePayload; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import org.jclouds.openstack.swift.v1.SwiftApi; +import org.jclouds.openstack.swift.v1.domain.Segment; +import org.jclouds.openstack.swift.v1.domain.SwiftObject; +import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.io.ByteSource; + +@Test(groups = "live", testName = "StaticLargeObjectApiLiveTest") +public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> { + + private String name = getClass().getSimpleName(); + private String containerName = getClass().getSimpleName() + "Container"; + private byte[] megOf1s; + private byte[] megOf2s; + + public void testNotPresentWhenDeleting() throws Exception { + for (String regionId : regions) { + api.getStaticLargeObjectApi(regionId, containerName).delete(UUID.randomUUID().toString()); + } + } + + public void testReplaceManifest() throws Exception { + for (String regionId : regions) { + ObjectApi objectApi = api.getObjectApi(regionId, containerName); + + String etag1s = objectApi.put(name + "/1", newByteSourcePayload(ByteSource.wrap(megOf1s))); + assertMegabyteAndETagMatches(regionId, name + "/1", etag1s); + + String etag2s = objectApi.put(name + "/2", newByteSourcePayload(ByteSource.wrap(megOf2s))); + assertMegabyteAndETagMatches(regionId, name + "/2", etag2s); + + List<Segment> segments = ImmutableList.<Segment> builder() + .add(Segment.builder() + .path(format("%s/%s/1", containerName, name)).etag(etag1s).sizeBytes(1024 * 1024) + .build()) + .add(Segment.builder() + .path(format("%s/%s/2", containerName, name)).etag(etag2s).sizeBytes(1024 * 1024) + .build()) + .build(); + + String etagOfEtags = api.getStaticLargeObjectApi(regionId, containerName).replaceManifest( + name, segments, ImmutableMap.of("myfoo", "Bar")); + + assertNotNull(etagOfEtags); + + SwiftObject bigObject = api.getObjectApi(regionId, containerName).get(name); + assertEquals(bigObject.getETag(), etagOfEtags); + assertEquals(bigObject.getPayload().getContentMetadata().getContentLength(), Long.valueOf(2 * 1024 * 1024)); + assertEquals(bigObject.getMetadata(), ImmutableMap.of("myfoo", "Bar")); + + // segments are visible + assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), 3); + } + } + + @Test(dependsOnMethods = "testReplaceManifest") + public void testDelete() throws Exception { + for (String regionId : regions) { + api.getStaticLargeObjectApi(regionId, containerName).delete(name); + assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), 0); + } + } + + protected void assertMegabyteAndETagMatches(String regionId, String name, String etag1s) { + SwiftObject object1s = api.getObjectApi(regionId, containerName).get(name); + assertEquals(object1s.getETag(), etag1s); + assertEquals(object1s.getPayload().getContentMetadata().getContentLength(), Long.valueOf(1024 * 1024)); + } + + @Override + @BeforeClass(groups = "live") + public void setup() { + super.setup(); + for (String regionId : regions) { + boolean created = api.getContainerApi(regionId).create(containerName); + if (!created) { + deleteAllObjectsInContainer(regionId, containerName); + } + } + + megOf1s = new byte[1024 * 1024]; + megOf2s = new byte[1024 * 1024]; + + Arrays.fill(megOf1s, (byte) 1); + Arrays.fill(megOf2s, (byte) 2); + } + + @Override + @AfterClass(groups = "live") + public void tearDown() { + for (String regionId : regions) { + deleteAllObjectsInContainer(regionId, containerName); + api.getContainerApi(regionId).deleteIfEmpty(containerName); + } + super.tearDown(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java new file mode 100644 index 0000000..c5627a6 --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java @@ -0,0 +1,107 @@ +/* + * 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 org.jclouds.openstack.swift.v1.features; + +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; +import static org.testng.Assert.assertEquals; + +import org.jclouds.openstack.swift.v1.SwiftApi; +import org.jclouds.openstack.swift.v1.domain.Segment; +import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.net.HttpHeaders; +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; +import com.squareup.okhttp.mockwebserver.RecordedRequest; + +@Test(groups = "unit", testName = "StaticLargeObjectApiMockTest") +public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> { + + public void testReplaceManifest() throws Exception { + MockWebServer server = mockOpenStackServer(); + server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); + server.enqueue(addCommonHeaders(new MockResponse().addHeader(HttpHeaders.ETAG, "\"abcd\""))); + + try { + SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + assertEquals( + api.getStaticLargeObjectApi("DFW", "myContainer").replaceManifest( + "myObject", + ImmutableList + .<Segment> builder() + .add(Segment.builder().path("/mycontainer/objseg1").etag("0228c7926b8b642dfb29554cd1f00963") + .sizeBytes(1468006).build()) + .add(Segment.builder().path("/mycontainer/pseudodir/seg-obj2") + .etag("5bfc9ea51a00b790717eeb934fb77b9b").sizeBytes(1572864).build()) + .add(Segment.builder().path("/other-container/seg-final") + .etag("b9c3da507d2557c1ddc51f27c54bae51").sizeBytes(256).build()).build(), + ImmutableMap.of("MyFoo", "Bar")), "abcd"); + + assertEquals(server.getRequestCount(), 2); + assertAuthentication(server); + + RecordedRequest replaceRequest = server.takeRequest(); + assertRequest(replaceRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=put"); + assertEquals(replaceRequest.getHeader(OBJECT_METADATA_PREFIX + "myfoo"), "Bar"); + assertEquals( + new String(replaceRequest.getBody()), + "[{\"path\":\"/mycontainer/objseg1\",\"etag\":\"0228c7926b8b642dfb29554cd1f00963\",\"size_bytes\":1468006}," + + "{\"path\":\"/mycontainer/pseudodir/seg-obj2\",\"etag\":\"5bfc9ea51a00b790717eeb934fb77b9b\",\"size_bytes\":1572864}," + + "{\"path\":\"/other-container/seg-final\",\"etag\":\"b9c3da507d2557c1ddc51f27c54bae51\",\"size_bytes\":256}]"); + } finally { + server.shutdown(); + } + } + + public void testDelete() throws Exception { + MockWebServer server = mockOpenStackServer(); + server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); + server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); + + try { + SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject"); + + assertEquals(server.getRequestCount(), 2); + assertAuthentication(server); + assertRequest(server.takeRequest(), "DELETE", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=delete"); + + } finally { + server.shutdown(); + } + } + + public void testAlreadyDeleted() throws Exception { + MockWebServer server = mockOpenStackServer(); + server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); + server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); + + try { + SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject"); + + assertEquals(server.getRequestCount(), 2); + assertAuthentication(server); + assertRequest(server.takeRequest(), "DELETE", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=delete"); + } finally { + server.shutdown(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java new file mode 100644 index 0000000..c811571 --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java @@ -0,0 +1,44 @@ +/* + * 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 org.jclouds.openstack.swift.v1.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.openstack.swift.v1.features.BulkApi.UrlEncodeAndJoinOnNewline; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +@Test(groups = "unit", testName = "UrlEncodeAndJoinOnNewlineTest") +public class UrlEncodeAndJoinOnNewlineTest { + UrlEncodeAndJoinOnNewline binder = new UrlEncodeAndJoinOnNewline(); + + public void urlEncodesPaths() { + HttpRequest request = HttpRequest.builder() + .method("DELETE") + .endpoint("https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_XXXXXX/") + .addQueryParam("bulk-delete").build(); + + request = binder.bindToRequest(request, ImmutableList.<String> builder() + .add("/v1/12345678912345/mycontainer/home/xx<yy") + .add("/v1/12345678912345/mycontainer/../image.gif").build()); + + assertEquals(request.getPayload().getRawContent(), "/v1/12345678912345/mycontainer/home/xx%3Cyy\n" + + "/v1/12345678912345/mycontainer/../image.gif"); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/internal/BaseSwiftApiLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/internal/BaseSwiftApiLiveTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/internal/BaseSwiftApiLiveTest.java new file mode 100644 index 0000000..a5cf538 --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/internal/BaseSwiftApiLiveTest.java @@ -0,0 +1,88 @@ +/* + * 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 org.jclouds.openstack.swift.v1.internal; + +import static com.google.common.base.Preconditions.checkState; + +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.apis.BaseApiLiveTest; +import org.jclouds.location.reference.LocationConstants; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.swift.v1.SwiftApi; +import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse; +import org.jclouds.openstack.swift.v1.domain.ObjectList; +import org.jclouds.openstack.swift.v1.domain.SwiftObject; +import org.jclouds.openstack.swift.v1.options.ListContainerOptions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Uninterruptibles; + +@Test(groups = "live", testName = "BaseSwiftApiLiveTest") +public abstract class BaseSwiftApiLiveTest<A extends SwiftApi> extends BaseApiLiveTest<A> { + + protected Set<String> regions; + + protected BaseSwiftApiLiveTest() { + provider = "openstack-swift"; + } + + @Override + @BeforeClass(groups = "live") + public void setup() { + super.setup(); + String providedRegion = System.getProperty("test." + LocationConstants.PROPERTY_REGION); + if (providedRegion != null) { + regions = ImmutableSet.of(providedRegion); + } else { + regions = api.getConfiguredRegions(); + } + } + + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE); + setIfTestSystemPropertyPresent(props, LocationConstants.PROPERTY_REGION); + return props; + } + + protected void deleteAllObjectsInContainer(String regionId, final String containerName) { + Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); + + ObjectList objects = api.getObjectApi(regionId, containerName).list(new ListContainerOptions()); + if (objects == null) { + return; + } + List<String> pathsToDelete = Lists.transform(objects, new Function<SwiftObject, String>() { + public String apply(SwiftObject input) { + return containerName + "/" + input.getName(); + } + }); + if (!pathsToDelete.isEmpty()) { + BulkDeleteResponse response = api.getBulkApi(regionId).bulkDelete(pathsToDelete); + checkState(response.getErrors().isEmpty(), "Errors deleting paths %s: %s", pathsToDelete, response); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java new file mode 100644 index 0000000..1da648b --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java @@ -0,0 +1,69 @@ +/* + * 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 org.jclouds.openstack.swift.v1.options; + +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_QUOTA_BYTES; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; + +/** + * Tests behavior of {@link CreateContainerOptions}. + */ +@Test(groups = "unit") +public class CreateContainerOptionsTest { + + public void testMetadata() { + CreateContainerOptions options = + new CreateContainerOptions().metadata(ImmutableMap.of("ApiName", "swift", "metaKey2", "Value2", "METAKEY3", "VALUE 3 ")); + + Multimap<String, String> headers = options.buildRequestHeaders(); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey2"), ImmutableList.of("Value2")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey3"), ImmutableList.of("VALUE 3 ")); + } + + public void testHeaders() { + CreateContainerOptions options = + new CreateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_QUOTA_BYTES, "5120", CONTAINER_METADATA_PREFIX + "apiname", "swift")); + + Multimap<String, String> headers = options.buildRequestHeaders(); + assertEquals(headers.get(CONTAINER_QUOTA_BYTES), ImmutableList.of("5120")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); + } + + public void testAnybodyRead() { + CreateContainerOptions options = + new CreateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ)); + assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); + } + + public void testVersionsLocation() { + CreateContainerOptions options = + new CreateContainerOptions().headers(ImmutableMultimap.of(VERSIONS_LOCATION, "containerWithVersions")); + assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java new file mode 100644 index 0000000..fddf4cd --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java @@ -0,0 +1,48 @@ +/* + * 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 org.jclouds.openstack.swift.v1.options; + +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_DELETE_AT; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; + +/** + * Tests behavior of {@link PutOptions}. + */ +@Test(groups = "unit") +public class PutOptionsTest { + + public void testPutMetadata() { + PutOptions options = + new PutOptions().metadata(ImmutableMap.of("ApiName", "swift")); + assertEquals(options.buildRequestHeaders().get(OBJECT_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); + + } + + public void testPutHeaders() { + PutOptions options = + new PutOptions().headers(ImmutableMultimap.of(OBJECT_DELETE_AT, "123456789")); + assertEquals(options.buildRequestHeaders().get(OBJECT_DELETE_AT), ImmutableList.of("123456789")); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java new file mode 100644 index 0000000..00f95f7 --- /dev/null +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java @@ -0,0 +1,122 @@ +/* + * 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 org.jclouds.openstack.swift.v1.options; + +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_QUOTA_BYTES; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_DIRECTORY_TYPE; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_ERROR; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_INDEX; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS; +import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS_CSS; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; +import com.google.common.net.MediaType; + +/** + * Tests behavior of {@link UpdateContainerOptions}. + */ +@Test(groups = "unit") +public class UpdateContainerOptionsTest { + + public void testAnybodyRead() { + UpdateContainerOptions options = new UpdateContainerOptions().anybodyRead(); + assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); + } + + public void testAnybodyReadViaHeaders() { + UpdateContainerOptions options = + new UpdateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ)); + assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); + } + + public void testVersionsLocation() { + UpdateContainerOptions options = new UpdateContainerOptions().versionsLocation("containerWithVersions"); + assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); + } + + public void testVersionsLocationViaHeaders() { + UpdateContainerOptions options = + new UpdateContainerOptions().headers(ImmutableMultimap.of(VERSIONS_LOCATION, "containerWithVersions")); + assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); + } + + public void testMetadata() { + UpdateContainerOptions options = + new UpdateContainerOptions().metadata(ImmutableMap.of("ApiName", "swift", "metaKey2", "Value2", "METAKEY3", "VALUE 3 ")); + + Multimap<String, String> headers = options.buildRequestHeaders(); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey2"), ImmutableList.of("Value2")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey3"), ImmutableList.of("VALUE 3 ")); + } + + public void testHeaders() { + UpdateContainerOptions options = + new UpdateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_QUOTA_BYTES, "5120", CONTAINER_METADATA_PREFIX + "apiname", "swift")); + + Multimap<String, String> headers = options.buildRequestHeaders(); + assertEquals(headers.get(CONTAINER_QUOTA_BYTES), ImmutableList.of("5120")); + assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); + } + + public void testStaticWebsiteDirectoryType() { + MediaType appDir = MediaType.create("application", "directory"); + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_DIRECTORY_TYPE, appDir.toString()); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_DIRECTORY_TYPE), ImmutableList.of(appDir.toString())); + } + + public void testStaticWebsiteIndexPage() { + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_INDEX, "index.html"); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_INDEX), ImmutableList.of("index.html")); + } + + public void testStaticWebsiteErrorPage() { + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_ERROR, "error.html"); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_ERROR), ImmutableList.of("error.html")); + } + + public void testEnableStaticWebsiteListings() { + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS, "true"); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS), ImmutableList.of("true")); + } + + public void testDiableStaticWebsiteListings() { + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS, "false"); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS), ImmutableList.of("false")); + } + + public void testStaticWebsiteListingsCSS() { + Multimap<String, String> headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS_CSS, "listings.css"); + UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); + assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS_CSS), ImmutableList.of("listings.css")); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/resources/access.json ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/resources/access.json b/apis/openstack-swift/src/test/resources/access.json new file mode 100644 index 0000000..8e0a69c --- /dev/null +++ b/apis/openstack-swift/src/test/resources/access.json @@ -0,0 +1,249 @@ +{ + "access":{ + "token":{ + "id":"bb03a23aa8271291a7aaa9aaa2aaaaaa", + "expires":"2013-08-02T16:55:24.229-05:00", + "tenant":{ + "id":"888888", + "name":"888888" + }, + "RAX-AUTH:authenticatedBy":[ + "PASSWORD" + ] + }, + "serviceCatalog":[ + { + "name":"cloudFilesCDN", + "endpoints":[ + { + "region":"ORD", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + }, + { + "region":"DFW", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + }, + { + "region":"SYD", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + } + ], + "type":"rax:object-cdn" + }, + { + "name":"cloudFiles", + "endpoints":[ + { + "region":"ORD", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + }, + { + "region":"DFW", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + }, + { + "region":"SYD", + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" + } + ], + "type":"object-store" + }, + { + "name":"cloudLoadBalancers", + "endpoints":[ + { + "region":"SYD", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + }, + { + "region":"DFW", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + }, + { + "region":"ORD", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + } + ], + "type":"rax:load-balancer" + }, + { + "name":"cloudDatabases", + "endpoints":[ + { + "region":"SYD", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + }, + { + "region":"DFW", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + }, + { + "region":"ORD", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + } + ], + "type":"rax:database" + }, + { + "name":"cloudBlockStorage", + "endpoints":[ + { + "region":"SYD", + "tenantId":"888888", + "publicURL":"URL/v1\/888888" + }, + { + "region":"DFW", + "tenantId":"888888", + "publicURL":"URL/v1\/888888" + }, + { + "region":"ORD", + "tenantId":"888888", + "publicURL":"URL/v1\/888888" + } + ], + "type":"volume" + }, + { + "name":"cloudServersOpenStack", + "endpoints":[ + { + "region":"SYD", + "tenantId":"888888", + "publicURL":"URL/v2\/888888", + "versionInfo":"https:\/\/syd.servers.api.rackspacecloud.com\/v2", + "versionList":"https:\/\/syd.servers.api.rackspacecloud.com\/", + "versionId":"2" + }, + { + "region":"DFW", + "tenantId":"888888", + "publicURL":"URL/v2\/888888", + "versionInfo":"https:\/\/dfw.servers.api.rackspacecloud.com\/v2", + "versionList":"https:\/\/dfw.servers.api.rackspacecloud.com\/", + "versionId":"2" + }, + { + "region":"ORD", + "tenantId":"888888", + "publicURL":"URL/v2\/888888", + "versionInfo":"https:\/\/ord.servers.api.rackspacecloud.com\/v2", + "versionList":"https:\/\/ord.servers.api.rackspacecloud.com\/", + "versionId":"2" + } + ], + "type":"compute" + }, + { + "name":"autoscale", + "endpoints":[ + { + "region":"ORD", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888", + "versionInfo":null, + "versionList":null, + "versionId":"1.0" + }, + { + "region":"DFW", + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888", + "versionInfo":null, + "versionList":null, + "versionId":"1.0" + } + ], + "type":"rax:autoscale" + }, + { + "name":"cloudMonitoring", + "endpoints":[ + { + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + } + ], + "type":"rax:monitor" + }, + { + "name":"cloudBackup", + "endpoints":[ + { + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + } + ], + "type":"rax:backup" + }, + { + "name":"cloudServers", + "endpoints":[ + { + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888", + "versionInfo":"https:\/\/servers.api.rackspacecloud.com\/v1.0", + "versionList":"https:\/\/servers.api.rackspacecloud.com\/", + "versionId":"1.0" + } + ], + "type":"compute" + }, + { + "name":"cloudDNS", + "endpoints":[ + { + "tenantId":"888888", + "publicURL":"URL/v1.0\/888888" + } + ], + "type":"rax:dns" + } + ], + "user":{ + "id":"335853", + "roles":[ + { + "id":"10000150", + "description":"Checkmate Access role", + "name":"checkmate" + }, + { + "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", + "id":"5", + "description":"A Role that allows a user access to keystone Service methods", + "name":"object-store:default" + }, + { + "tenantId":"888888", + "id":"6", + "description":"A Role that allows a user access to keystone Service methods", + "name":"compute:default" + }, + { + "id":"3", + "description":"User Admin Role.", + "name":"identity:user-admin" + } + ], + "name":"test", + "RAX-AUTH:defaultRegion":"ORD" + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/resources/container_list.json ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/resources/container_list.json b/apis/openstack-swift/src/test/resources/container_list.json new file mode 100644 index 0000000..554f5de --- /dev/null +++ b/apis/openstack-swift/src/test/resources/container_list.json @@ -0,0 +1,12 @@ +[ + { + "name": "test_container_1", + "count": 2, + "bytes": 78 + }, + { + "name": "test_container_2", + "count": 1, + "bytes": 17 + } +] http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/resources/logback.xml ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/resources/logback.xml b/apis/openstack-swift/src/test/resources/logback.xml new file mode 100644 index 0000000..ce891f1 --- /dev/null +++ b/apis/openstack-swift/src/test/resources/logback.xml @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<configuration scan="false"> + <appender name="FILE" class="ch.qos.logback.core.FileAppender"> + <file>target/test-data/jclouds.log</file> + + <encoder> + <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern> + </encoder> + </appender> + + <appender name="WIREFILE" class="ch.qos.logback.core.FileAppender"> + <file>target/test-data/jclouds-wire.log</file> + + <encoder> + <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern> + </encoder> + </appender> + + <appender name="BLOBSTOREFILE" class="ch.qos.logback.core.FileAppender"> + <file>target/test-data/jclouds-blobstore.log</file> + + <encoder> + <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern> + </encoder> + </appender> + + <root> + <level value="warn" /> + </root> + + <logger name="org.jclouds"> + <level value="DEBUG" /> + <appender-ref ref="FILE" /> + </logger> + +<!-- + <logger name="jclouds.wire"> + <level value="DEBUG" /> + <appender-ref ref="WIREFILE" /> + </logger> +--> + + <logger name="jclouds.headers"> + <level value="DEBUG" /> + <appender-ref ref="WIREFILE" /> + </logger> + + <logger name="jclouds.blobstore"> + <level value="DEBUG" /> + <appender-ref ref="BLOBSTOREFILE" /> + </logger> + +</configuration> http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/openstack-swift/src/test/resources/object_list.json ---------------------------------------------------------------------- diff --git a/apis/openstack-swift/src/test/resources/object_list.json b/apis/openstack-swift/src/test/resources/object_list.json new file mode 100644 index 0000000..afe8c77 --- /dev/null +++ b/apis/openstack-swift/src/test/resources/object_list.json @@ -0,0 +1,23 @@ +[ + { + "name": "test_obj_1", + "hash": "4281c348eaf83e70ddce0e07221c3d28", + "bytes": 14, + "content_type": "application/octet-stream", + "last_modified": "2009-02-03T05:26:32.612278" + }, + { + "name": "test_obj_2", + "hash": "b039efe731ad111bc1b0ef221c3849d0", + "bytes": 64, + "content_type": "application/octet-stream", + "last_modified": "2009-02-03T05:26:32.612278" + }, + { + "name": "test obj 3", + "hash": "0b2e80bd0744d9ebb20484149a57c82e", + "bytes": 123, + "content_type": "application/octet-stream", + "last_modified": "2014-05-20T05:26:32.612278" + } +] http://git-wip-us.apache.org/repos/asf/jclouds/blob/34663f3c/apis/pom.xml ---------------------------------------------------------------------- diff --git a/apis/pom.xml b/apis/pom.xml index 32722fe..5226afe 100644 --- a/apis/pom.xml +++ b/apis/pom.xml @@ -45,6 +45,7 @@ <module>openstack-cinder</module> <module>openstack-nova</module> <module>openstack-nova-ec2</module> + <module>openstack-swift</module> <module>openstack-trove</module> <module>cloudfiles</module> <module>cloudservers</module>
