Author: angelo.vandersijpt at luminis.eu
Date: Thu Oct 28 14:03:20 2010
New Revision: 215

Log:
AMDATU-121 ...and add two new files.

Added:
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/InMemoryTenantStorageProvider.java
   
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/TenantStorageException.java

Added: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/InMemoryTenantStorageProvider.java
==============================================================================
--- (empty file)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/InMemoryTenantStorageProvider.java
   Thu Oct 28 14:03:20 2010
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.test.integration.mock;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.amdatu.platform.tenant.TenantEntity;
+import org.amdatu.platform.tenant.TenantStorageProvider;
+
+/**
+ * This service provides an in-memory implementation of the 
TenantStorageProvider, used for unit testing.
+ */
+public class InMemoryTenantStorageProvider implements TenantStorageProvider {
+    private final Map<String, TenantEntity> m_tenants = new HashMap<String, 
TenantEntity>();
+
+    public List<TenantEntity> getAll() {
+        return new ArrayList<TenantEntity>(m_tenants.values());
+    }
+
+    public TenantEntity getById(String id) {
+        return copy(m_tenants.get(id));
+    }
+
+    public void store(TenantEntity tenant) {
+        m_tenants.put(tenant.getId(), copy(tenant));
+    }
+
+    public void delete(TenantEntity tenant) {
+        m_tenants.remove(tenant.getId());
+    }
+
+    private TenantEntity copy(TenantEntity tenant) {
+        if (tenant == null) {
+            return null;
+        }
+        return new TenantEntity(tenant.getId(), tenant.getName(), new 
HashMap<String, String>(tenant.getProperties()));
+    }
+}

Added: 
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/TenantStorageException.java
==============================================================================
--- (empty file)
+++ 
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/TenantStorageException.java
  Thu Oct 28 14:03:20 2010
@@ -0,0 +1,14 @@
+package org.amdatu.platform.tenant;
+
+/**
+ * This exception signifies a problem in reading or writing from/to the 
persistent storage.
+ */
+public class TenantStorageException extends TenantException {
+    public TenantStorageException(Exception e) {
+        super(e);
+    }
+
+    public TenantStorageException(String msg) {
+        super(msg);
+    }
+}

Reply via email to