Author: adietish
Date: 2010-10-20 15:41:24 -0400 (Wed, 20 Oct 2010)
New Revision: 25954
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/DeltaCloudClientTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/ServerFake.java
Removed:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/
Log:
[JBIDE-7371] all tests for server type implemented
Copied:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/DeltaCloudClientTest.java
(from rev 25944,
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/DeltaCloudClientTest.java)
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/DeltaCloudClientTest.java
(rev 0)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/DeltaCloudClientTest.java 2010-10-20
19:41:24 UTC (rev 25954)
@@ -0,0 +1,54 @@
+package org.jboss.tools.internal.deltacloud.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.internal.deltacloud.test.fakes.ServerFake;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DeltaCloudClientTest {
+
+ private static final String DELTACLOUD_URL = "http://localhost:3001";
+ private static final String SERVERFAKE_URL = "http://localhost:3002";
+ private static final String DELTACLOUD_USER = "user";
+ private static final String DELTACLOUD_PASSWORD = "password";
+
+ private DeltaCloudClient client;
+ private DeltaCloudClient fakeServerClient;
+
+ @Before
+ public void createDeltaCloudClient() throws MalformedURLException {
+ this.client = new DeltaCloudClient(new URL(DELTACLOUD_URL), DELTACLOUD_USER,
DELTACLOUD_PASSWORD);
+ this.fakeServerClient = new DeltaCloudClient(new URL(SERVERFAKE_URL), DELTACLOUD_USER,
DELTACLOUD_PASSWORD);
+ }
+
+ @Test
+ public void isDeltaCloudRunning() throws MalformedURLException, IOException {
+ URLConnection connection = new URL(DELTACLOUD_URL).openConnection();
+ connection.connect();
+ }
+
+ @Test
+ public void canRecognizeMockDeltaCloud() throws IOException {
+ assertEquals(DeltaCloudClient.DeltaCloudType.MOCK, new DeltaCloudClient(DELTACLOUD_URL,
DELTACLOUD_USER, DELTACLOUD_PASSWORD).getServerType());
+ }
+
+ @Test
+ public void reportsUnknownUrl() throws IOException {
+ ServerFake serverFake = new ServerFake(new URL(SERVERFAKE_URL).getPort(),
"<dummy></dummy>");
+ serverFake.start();
+ try {
+ assertEquals(DeltaCloudClient.DeltaCloudType.UNKNOWN, new
DeltaCloudClient(SERVERFAKE_URL, DELTACLOUD_USER, DELTACLOUD_PASSWORD).getServerType());
+ } finally {
+ serverFake.stop();
+ }
+ }
+}
Property changes on:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/DeltaCloudClientTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/ServerFake.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/ServerFake.java
(rev 0)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/ServerFake.java 2010-10-20
19:41:24 UTC (rev 25954)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.internal.deltacloud.test.fakes;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class ServerFake {
+
+ private ExecutorService executor;
+ private int port;
+ private String response;
+
+ public ServerFake(int port, String response) {
+ this.port = port;
+ this.response = response;
+ }
+
+ public void start() {
+ executor = Executors.newFixedThreadPool(1);
+ executor.submit(new ServerFakeSocket(port, response));
+ }
+
+ public void stop() {
+ executor.shutdownNow();
+ }
+
+ private class ServerFakeSocket implements Runnable {
+ private String response;
+ private ServerSocket serverSocket;
+
+ private ServerFakeSocket(int port, String response) {
+
+ this.response = response;
+
+ try {
+ this.serverSocket = new ServerSocket(port);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void run() {
+ Socket socket;
+ try {
+ socket = serverSocket.accept();
+ OutputStream outputStream = socket.getOutputStream();
+ outputStream.write(response.getBytes());
+ outputStream.flush();
+ socket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/fakes/ServerFake.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain