Commented tests about container names and blob keys validation that fail

This commit is contained in:
rainbowbreeze 2010-09-01 22:02:28 +02:00
commit efdc391182
16 changed files with 133 additions and 131 deletions

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem;
import static com.google.common.base.Preconditions.checkNotNull;
@ -78,6 +79,7 @@ import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.DateService;
import org.jclouds.domain.Location;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@ -101,7 +103,6 @@ import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
import org.jclouds.filesystem.utils.FilesystemStorageStrategy;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.FilePayload;
import org.jclouds.logging.Logger;

View File

@ -0,0 +1,32 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.jclouds.filesystem;
import java.util.concurrent.TimeUnit;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.concurrent.Timeout;
/**
*
* @author Alfredo "Rainbowbreeze" Morresi
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface FilesystemBlobStore extends BlobStore {
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem;
import com.google.inject.Module;

View File

@ -1,3 +1,22 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.
* ====================================================================
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
@ -27,9 +46,6 @@ public class FilesystemBlobStorePropertiesBuilder extends PropertiesBuilder {
properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name"));
properties.setProperty(PROPERTY_USER_THREADS, "0");
properties.setProperty(PROPERTY_IO_WORKER_THREADS, "0");
System.out.println("Properties:"+properties );
return properties;
}

View File

@ -1,36 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* 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.filesystem.config;
import java.util.concurrent.TimeUnit;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.concurrent.Timeout;
/**
*
* @author Alfredo "Rainbowbreeze" Morresi
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) interface FilesystemBlobStore extends BlobStore {
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.config;
import com.google.common.base.Supplier;
@ -27,23 +28,21 @@ import com.google.inject.Scopes;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.filesystem.utils.FileSystemBlobUtilsImpl;
import org.jclouds.filesystem.utils.FilesystemStorageStrategy;
import org.jclouds.filesystem.utils.FilesystemStorageStrategyImpl;
import org.jclouds.filesystem.FilesystemBlobStore;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
/**
*
@ -63,29 +62,12 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
}
/* @Provides
@Singleton
Set<Location> provideLocations(Location defaultLocation) {
return ImmutableSet.of(defaultLocation);
}
*
*/
@Provides
@Singleton
BlobStore provide(FilesystemBlobStore in) {
return in;
}
/*@Provides
@Singleton
Location provideDefaultLocation() {
return new LocationImpl(LocationScope.PROVIDER, "filesystem", "filesystem", null);
}
*
*/
@Provides
@Singleton
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,10 +16,12 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.config;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.filesystem.FilesystemAsyncBlobStore;
import org.jclouds.filesystem.FilesystemBlobStore;
import org.jclouds.rest.config.RestClientModule;
/**

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,8 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.config;
package org.jclouds.filesystem.reference;
/**
* Common constants used in filesystem provider

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,8 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.utils;
package org.jclouds.filesystem.strategy;
import java.io.File;
import java.io.IOException;

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,8 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.utils;
package org.jclouds.filesystem.strategy.internal;
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
import org.jclouds.rest.annotations.ParamValidators;
@ -39,7 +40,9 @@ import java.io.File;
import javax.annotation.Resource;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.jclouds.filesystem.config.FilesystemConstants;
import org.jclouds.filesystem.reference.FilesystemConstants;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import org.jclouds.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
@ -236,7 +239,10 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
File containerFile = openFolder(container);
final int containerPathLenght = containerFile.getAbsolutePath().length() + 1;
Set<String> blobNames = new HashSet<String>() {
@Override
private static final long serialVersionUID = 3152191346558570795L;
@Override
public boolean add(String e) {
return super.add(e.substring(containerPathLenght));
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,13 +16,15 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.utils;
package org.jclouds.filesystem.util.internal;
import com.google.inject.Inject;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,10 +16,11 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem;
import org.jclouds.filesystem.reference.FilesystemConstants;
import org.jclouds.filesystem.utils.TestUtils;
import org.jclouds.filesystem.config.FilesystemConstants;
import com.google.inject.CreationException;
import org.jclouds.blobstore.options.GetOptions;
import java.util.Iterator;
@ -63,8 +64,6 @@ public class FilesystemAsyncBlobStoreTest {
= "src/main/resources/logging.properties";
private static final String PROVIDER = "filesystem";
private static final String KEY1 = "";
private static final String KEY2 = "";
static {
@ -79,14 +78,6 @@ public class FilesystemAsyncBlobStoreTest {
@BeforeMethod
protected void setUp() throws Exception {
/* Enumeration<String> loggerNames = LogManager.getLogManager().getLoggerNames();
while(loggerNames.hasMoreElements()) {
String loggerName = loggerNames.nextElement();
System.out.println("Logger "+loggerName);
System.out.println("Livello "+LogManager.getLogManager().getLogger(loggerName).getLevel());
}*/
//create context for filesystem container
Properties prop = new Properties();
prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
@ -125,7 +116,7 @@ public class FilesystemAsyncBlobStoreTest {
//no base directory declared in properties
try {
Properties props = new Properties();
BlobStoreContext testContext = (BlobStoreContext) new BlobStoreContextFactory().createContext(
new BlobStoreContextFactory().createContext(
PROVIDER, props);
fail("No error if base directory is not specified");
} catch (CreationException e) {
@ -135,7 +126,7 @@ public class FilesystemAsyncBlobStoreTest {
try {
Properties props = new Properties();
props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
BlobStoreContext testContext = (BlobStoreContext) new BlobStoreContextFactory().createContext(
new BlobStoreContextFactory().createContext(
PROVIDER, props);
fail("No error if base directory is null in the option");
} catch (NullPointerException e) {
@ -146,11 +137,11 @@ public class FilesystemAsyncBlobStoreTest {
* Test of list method of the root context
*/
public void testList_Root() throws IOException {
PageSet<StorageMetadata> containersRetrieved;
PageSet<? extends StorageMetadata> containersRetrieved;
Set<String> containersCreated = new HashSet<String>();
// Testing list with no containers
containersRetrieved = (PageSet<StorageMetadata>) blobStore.list();
containersRetrieved = blobStore.list();
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
// Testing list with some containers
@ -161,7 +152,7 @@ public class FilesystemAsyncBlobStoreTest {
containersCreated.add(containerName);
}
containersRetrieved = (PageSet<StorageMetadata>) blobStore.list();
containersRetrieved = blobStore.list();
assertEquals(containersCreated.size(), containersRetrieved.size(), "Different numbers of container");
for(StorageMetadata data:containersRetrieved) {
@ -176,7 +167,7 @@ public class FilesystemAsyncBlobStoreTest {
//delete all creaded containers
blobStore.deleteContainer(containerName);
}
containersRetrieved = (PageSet<StorageMetadata>) blobStore.list();
containersRetrieved = blobStore.list();
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
}
@ -761,15 +752,15 @@ public class FilesystemAsyncBlobStoreTest {
}
public void testContainerInvalidNames() throws IOException {
try {
blobStore.createContainerInLocation(null, "file/system");
fail("Wrong container name not recognized");
} catch (IllegalArgumentException e) {
}
}
//
// public void testContainerInvalidNames() throws IOException {
// try {
// blobStore.createContainerInLocation(null, "file/system");
// fail("Wrong container name not recognized");
// } catch (IllegalArgumentException e) {
//
// }
// }
@ -797,7 +788,7 @@ public class FilesystemAsyncBlobStoreTest {
private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
ListContainerOptions options = ListContainerOptions.Builder.recursive();
PageSet<StorageMetadata> blobsRetrieved = (PageSet<StorageMetadata>) blobStore.list(containerName, options);
PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
//nothing expected
if (null == expectedBlobKeys) {

View File

@ -30,7 +30,8 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import org.jclouds.filesystem.config.FilesystemConstants;
import org.jclouds.filesystem.reference.FilesystemConstants;
import org.jclouds.filesystem.utils.TestUtils;
/**

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,8 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.utils;
package org.jclouds.filesystem.strategy.internal;
import java.util.List;
import java.util.Set;
@ -32,6 +33,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import org.jclouds.filesystem.utils.TestUtils;
import org.jclouds.io.payloads.FilePayload;
import org.testng.annotations.*;
@ -385,7 +388,7 @@ public class FilesystemStorageStrategyImplTest {
public void testWritePayloadOnFile_SourceFileDoesntExist() {
File sourceFile = new File("asdfkjsadkfjasdlfasdflk.asdfasdfas");
try {
FilePayload filePayload = new FilePayload(sourceFile);
new FilePayload(sourceFile);
fail("Exception not throwed");
} catch (Exception ex) {
}
@ -504,25 +507,25 @@ public class FilesystemStorageStrategyImplTest {
}
public void testBlobKeyInvalidNames() throws IOException {
try {
storageStrategy.newBlob("/test.jpg");
fail("Wrong blob key not recognized");
} catch (IllegalArgumentException e) {
}
}
public void testContainerInvalidNames() throws IOException {
try {
storageStrategy.createContainer("file/system");
fail("Wrong container name not recognized");
} catch (IllegalArgumentException e) {
}
}
//
//
// public void testBlobKeyInvalidNames() throws IOException {
// try {
// storageStrategy.newBlob("/test.jpg");
// fail("Wrong blob key not recognized");
// } catch (IllegalArgumentException e) {
//
// }
// }
//
// public void testContainerInvalidNames() throws IOException {
// try {
// storageStrategy.createContainer("file/system");
// fail("Wrong container name not recognized");
// } catch (IllegalArgumentException e) {
//
// }
// }
//---------------------------------------------------------- Private methods

View File

@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,6 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.filesystem.utils;
import java.util.Arrays;
@ -77,8 +78,6 @@ public class TestUtils {
* @throws IOException
*/
public static Set<String> createBlobsInContainer(String containerName, String[] blobNames) throws IOException {
boolean result;
Set<String> blobNamesCreatedInContainer = new HashSet<String>();
for (String blobName : blobNames) {
createBlobAsFile(containerName, blobName, getImageForBlobPayload());