Skip to content

Commit

Permalink
#296 core 81 and SelfJsonStorage sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed May 7, 2021
1 parent 6030d06 commit 36a8530
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>Self XDSD Storage Module</name>
<description>Storage Module for Self XDSD</description>
<properties>
<self.core.version>0.0.72</self.core.version>
<self.core.version>0.0.81</self.core.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/selfxdsd/storage/SelfJooq.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.selfxdsd.storage;

import com.selfxdsd.api.*;
import com.selfxdsd.api.storage.JsonStorage;
import com.selfxdsd.api.storage.Storage;

/**
Expand Down Expand Up @@ -135,6 +136,11 @@ public Payments payments() {
return new SelfPayments(this, this.database);
}

@Override
public JsonStorage jsonStorage() {
return new SelfJsonStorage(this, this.database);
}

@Override
public void close() {
this.database.close();
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/com/selfxdsd/storage/SelfJsonStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.storage;

import com.selfxdsd.api.storage.JsonStorage;
import com.selfxdsd.api.storage.Storage;

import java.net.URI;

/**
* Storage for JsonResources in Self XDSD (we store JSONs received from
* providers' API for making conditional requests using E-Tag).
* @author Mihai Andronache (amihaiemil@gmail.com)
* @since 0.0.70
* @version $Id$
*/
public final class SelfJsonStorage implements JsonStorage {

/**
* Parent Storage.
*/
private final Storage storage;

/**
* Database.
*/
private final Database database;

/**
* Ctor.
* @param storage Parent Storage.
* @param database Database.
*/
public SelfJsonStorage(
final Storage storage,
final Database database
) {
this.storage = storage;
this.database = database;
}

@Override
public String getEtag(final URI uri) {
return null;
}

@Override
public String getResourceBody(final URI uri) {
return null;
}

@Override
public void store(final URI uri, final String etag, final String resource) {

}
}
15 changes: 15 additions & 0 deletions src/test/java/com/selfxdsd/storage/SelfJooqTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,19 @@ public void returnsPayments() {
)
);
}

/**
* SelfJooq can return the JsonStorage.
*/
@Test
public void returnsJsonStorage() {
final Storage storage = new SelfJooq(Mockito.mock(Database.class));
MatcherAssert.assertThat(
storage.jsonStorage(),
Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(SelfJsonStorage.class)
)
);
}
}

0 comments on commit 36a8530

Please sign in to comment.