Skip to content
Snippets Groups Projects
Commit 7e23b6d0 authored by Adam Laskowski's avatar Adam Laskowski
Browse files

SSDM-13251: Created a simple unit test for client

parent 76b7b30e
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -24,7 +24,5 @@ dependencies {
implementation project(':lib-json'),
'lombok:lombok:1.18.22'
testImplementation 'junit:junit:4.10'
// project(':server-data-store'),
// project(':lib-transactional-file-system')
testRuntimeOnly 'hamcrest:hamcrest-core:1.3'
}
includeFlat 'lib-json'
//, 'lib-transactional-file-system', 'server-data-store'
......@@ -3,99 +3,109 @@ package ch.ethz.sis.afsclient.client;
import static org.junit.Assert.*;
import java.net.URI;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
//import ch.ethz.sis.afs.manager.TransactionConnection;
//import ch.ethz.sis.afsserver.server.Server;
//import ch.ethz.sis.afsserver.server.observer.impl.DummyServerObserver;
//import ch.ethz.sis.afsserver.startup.AtomicFileSystemServerParameter;
//import ch.ethz.sis.shared.startup.Configuration;
public class AfsClientTest
{
// private static Server<TransactionConnection, ?> afsServer;
private static DummyHttpServer httpServer;
private static AfsClient afsClient;
private static int httpServerPort;
private static String httpServerPath;
@BeforeClass
public static void classSetUp() throws Exception {
// final Configuration configuration = new Configuration(List.of(AtomicFileSystemServerParameter.class),
// "src/test/resources/afs-server-config.properties");
// final DummyServerObserver dummyServerObserver = new DummyServerObserver();
// afsServer = new Server<>(configuration, dummyServerObserver, dummyServerObserver);
//
// final int httpServerPort = configuration.getIntegerProperty(AtomicFileSystemServerParameter.httpServerPort);
// final String httpServerPath = configuration.getStringProperty(AtomicFileSystemServerParameter.httpServerUri);
// afsClient = new AfsClient(new URI("http", null, "localhost", httpServerPort, httpServerPath, null, null));
public static void classSetUp() throws Exception
{
httpServerPort = 8085;
httpServerPath = "/fileserver";
httpServer = new DummyHttpServer(httpServerPort, httpServerPath);
httpServer.start();
afsClient = new AfsClient(
new URI("http", null, "localhost", httpServerPort, httpServerPath, null, null));
}
@AfterClass
public static void classTearDown() throws Exception {
// afsServer.shutdown(true);
public static void classTearDown() throws Exception
{
httpServer.stop();
}
@Test
public void testLogin() throws Exception {
// final String token = afsClient.login("test", "test");
String token = "null";
public void testLogin() throws Exception
{
final String token = afsClient.login("test", "test");
assertNotNull(token);
}
@Test
public void testIsSessionValid() {
public void testIsSessionValid()
{
}
@Test
public void testLogout() {
public void testLogout()
{
}
@Test
public void testList() {
public void testList()
{
}
@Test
public void testRead() {
public void testRead()
{
}
@Test
public void testWrite() {
public void testWrite()
{
}
@Test
public void testDelete() {
public void testDelete()
{
}
@Test
public void testCopy() {
public void testCopy()
{
}
@Test
public void testMove() {
public void testMove()
{
}
@Test
public void testBegin() {
public void testBegin()
{
}
@Test
public void testPrepare() {
public void testPrepare()
{
}
@Test
public void testCommit() {
public void testCommit()
{
}
@Test
public void testRollback() {
public void testRollback()
{
}
@Test
public void testRecover() {
public void testRecover()
{
}
}
\ No newline at end of file
/*
* Copyright ETH 2023 Zürich, Scientific IT Services
*
* 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 ch.ethz.sis.afsclient.client;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public final class DummyHttpServer
{
private HttpServer httpServer;
private final int httpServerPort; // 8085
private final String httpServerPath; // "/fileserver"
private static final String DEFAULT_RESPONSE = "{\"result\": \"success\"}";
private String nextResponse = DEFAULT_RESPONSE;
public DummyHttpServer(int httpServerPort, String httpServerPath) throws IOException
{
this.httpServerPort = httpServerPort;
this.httpServerPath = httpServerPath;
httpServer = HttpServer.create(new InetSocketAddress(httpServerPort), 0);
httpServer.createContext(httpServerPath, new HttpHandler()
{
public void handle(HttpExchange exchange) throws IOException
{
byte[] response = nextResponse.getBytes();
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length);
exchange.getResponseBody().write(response);
exchange.close();
}
});
}
public void start()
{
httpServer.start();
}
public void stop()
{
httpServer.stop(0);
}
public void setNextResponse(String response)
{
this.nextResponse = response;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment