Skip to content

Commit

Permalink
Community module for S3 BlobStore
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsCharlier committed Jul 3, 2015
1 parent 417663f commit 0fbd0f3
Show file tree
Hide file tree
Showing 23 changed files with 663 additions and 181 deletions.
113 changes: 113 additions & 0 deletions src/community/gwc-s3/pom.xml
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- set parent pom to community pom -->
<parent>
<groupId>org.geoserver</groupId>
<artifactId>community</artifactId>
<version>2.8-SNAPSHOT</version>
</parent>

<groupId>org.geoserver.community</groupId>
<artifactId>gs-gwc-s3</artifactId>
<packaging>jar</packaging>
<version>2.8-SNAPSHOT</version>
<name>GeoWebCache S3</name>
<description>GeoWebCache S3 support plugin</description>

<dependencies>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-gwc</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.geoserver.web</groupId>
<artifactId>gs-web-gwc</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.geowebcache</groupId>
<artifactId>gwc-aws-s3</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-wms</artifactId>
<classifier>tests</classifier>
<version>${gs.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver.web</groupId>
<artifactId>gs-web-core</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.html</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</project>

@@ -0,0 +1,33 @@
package org.geoserver.gwc.web.blob;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.geowebcache.s3.S3BlobStoreConfig;

public class S3BlobStoreType implements BlobStoreType<S3BlobStoreConfig> {
private static final long serialVersionUID = 7349157660150568235L;

@Override
public String toString(){
return "S3 BlobStore";
}

@Override
public S3BlobStoreConfig newConfigObject() {
S3BlobStoreConfig config = new S3BlobStoreConfig();
config.setEnabled(true);
config.setMaxConnections(50);
return config;
}

@Override
public Class<S3BlobStoreConfig> getConfigClass() {
return S3BlobStoreConfig.class;
}

@Override
public Panel createPanel(String id, IModel<S3BlobStoreConfig> model) {
return new S3BlobStorePanel(id, model);
}

}
@@ -1,13 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2014 - Open Source Geospatial Foundation. All rights reserved.
This code is licensed under the GPL 2.0 license, available at the root
application directory.
-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<description>
Bean configuration file for the gwc-aws-s3 module
</description>

<bean id="S3BlobStoreConfigProvider" class="org.geowebcache.s3.S3BlobStoreConfigProvider">
<description>
Contributes XStream configuration settings to org.geowebcache.config.XMLConfiguration to encode S3BlobStoreConfig instances
</description>
</bean>

<bean class="org.geoserver.gwc.web.blob.S3BlobStoreType" />
</beans>
@@ -0,0 +1,129 @@
/* (c) 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.gwc.web.blob;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.util.tester.FormTester;
import org.geoserver.gwc.GWC;
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geowebcache.config.BlobStoreConfig;
import org.geowebcache.config.ConfigurationException;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.s3.S3BlobStoreConfig;
import org.junit.Test;

/**
*
* Test for the BlobStorePage with S3 BlobStore Panel
*
* @author Niels Charlier
*
*/
public class S3BlobStorePageTest extends GeoServerWicketTestSupport {


@Test
public void testPage() {
BlobStorePage page = new BlobStorePage();

tester.startPage(page);
tester.assertRenderedPage(BlobStorePage.class);

tester.assertComponent("selector", Form.class);
tester.assertComponent("selector:typeOfBlobStore", DropDownChoice.class);
tester.assertComponent("blobConfigContainer", MarkupContainer.class);

tester.assertInvisible("blobConfigContainer:blobStoreForm");

DropDownChoice typeOfBlobStore = (DropDownChoice) tester.getComponentFromLastRenderedPage("selector:typeOfBlobStore");
assertEquals(2, typeOfBlobStore.getChoices().size());
assertEquals("File BlobStore", typeOfBlobStore.getChoices().get(0).toString());
assertEquals("S3 BlobStore", typeOfBlobStore.getChoices().get(1).toString());

executeAjaxEventBehavior("selector:typeOfBlobStore", "onchange", "0");

tester.assertVisible("blobConfigContainer:blobStoreForm");
tester.assertComponent("blobConfigContainer:blobStoreForm:blobSpecificPanel", FileBlobStorePanel.class);

executeAjaxEventBehavior("selector:typeOfBlobStore", "onchange", "1");
tester.assertComponent("blobConfigContainer:blobStoreForm:blobSpecificPanel", S3BlobStorePanel.class);
}

@Test
public void testNew() throws ConfigurationException {
BlobStorePage page = new BlobStorePage();

tester.startPage(page);
executeAjaxEventBehavior("selector:typeOfBlobStore", "onchange", "1");

FormTester formTester = tester.newFormTester("blobConfigContainer:blobStoreForm");
formTester.setValue("id", "myblobstore");
formTester.setValue("enabled", false);
formTester.setValue("blobSpecificPanel:bucket", "mybucket");
formTester.setValue("blobSpecificPanel:awsAccessKey", "myaccesskey");
formTester.setValue("blobSpecificPanel:awsSecretKey", "mysecretkey");
tester.executeAjaxEvent("blobConfigContainer:blobStoreForm:save", "onclick");

List<BlobStoreConfig> blobStores = GWC.get().getBlobStores();
BlobStoreConfig config = blobStores.get(0);
assertTrue(config instanceof S3BlobStoreConfig);
assertEquals("myblobstore", config.getId());
assertEquals("mybucket", ((S3BlobStoreConfig) config).getBucket());
assertEquals("myaccesskey", ((S3BlobStoreConfig) config).getAwsAccessKey());
assertEquals("mysecretkey", ((S3BlobStoreConfig) config).getAwsSecretKey());
assertEquals(50, ((S3BlobStoreConfig) config).getMaxConnections().intValue());

GWC.get().removeBlobStores(Collections.singleton("myblobstore"));
}

@Test
public void testModify() throws Exception {
S3BlobStoreConfig sconfig = new S3BlobStoreConfig();
Field id = BlobStoreConfig.class.getDeclaredField("id");
id.setAccessible(true);
id.set(sconfig, "myblobstore");
sconfig.setMaxConnections(50);
sconfig.setBucket("mybucket");
sconfig.setAwsAccessKey("myaccesskey");
sconfig.setAwsSecretKey("mysecretkey");
GWC.get().addBlobStore(sconfig);
TileLayer layer = GWC.get().getTileLayerByName("cite:Lakes");
layer.setBlobStoreId("myblobstore");
GWC.get().save(layer);

BlobStorePage page = new BlobStorePage(sconfig);

tester.startPage(page);
tester.assertVisible("blobConfigContainer:blobStoreForm");
tester.assertComponent("blobConfigContainer:blobStoreForm:blobSpecificPanel", S3BlobStorePanel.class);

FormTester formTester = tester.newFormTester("blobConfigContainer:blobStoreForm");
formTester.setValue("id", "yourblobstore");
formTester.setValue("blobSpecificPanel:bucket", "yourbucket");
formTester.submit();
tester.executeAjaxEvent("blobConfigContainer:blobStoreForm:save", "onclick");

BlobStoreConfig config = GWC.get().getBlobStores().get(0);
assertTrue(config instanceof S3BlobStoreConfig);
assertEquals("yourblobstore", config.getId());
assertEquals("yourbucket", ((S3BlobStoreConfig) config).getBucket());

//test updated id!
layer = GWC.get().getTileLayerByName("cite:Lakes");
assertEquals("yourblobstore", layer.getBlobStoreId());

GWC.get().removeBlobStores(Collections.singleton("yourblobstore"));
}

}

0 comments on commit 0fbd0f3

Please sign in to comment.