package com.orientechnologies.orient.test.server.network.http;

import com.orientechnologies.orient.core.record.impl.ODocument;
import org.apache.http.HttpResponse;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

public class HttpServerTest extends BaseHttpDatabaseTest {
  @Test
  public void testGetServer() throws Exception {
    HttpResponse res = get("server").getResponse();
    Assert.assertEquals(res.getStatusLine().getStatusCode(), 200);

    ODocument payload = new ODocument().fromJSON(res.getEntity().getContent());

    Assert.assertTrue(payload.containsField("connections"));
  }

  @Test
  public void testGetConnections() throws Exception {
    HttpResponse res =
        setUserName("root").setUserPassword("root").get("connections/").getResponse();
    Assert.assertEquals(res.getStatusLine().getStatusCode(), 200);

    ODocument payload = new ODocument().fromJSON(res.getEntity().getContent());

    Assert.assertTrue(payload.containsField("connections"));
  }

  @Test
  public void testCreateDatabase() throws IOException {
    String dbName = getClass().getSimpleName()+"testCreateDatabase";
    HttpResponse res =
            setUserName("root")
                    .setUserPassword("root")
                    .post("servercommand")
                    .payload("{\"command\":\"create database "+dbName+" plocal\" }", CONTENT.JSON)
                    .getResponse();
    System.out.println(res.getStatusLine().getReasonPhrase());
    Assert.assertEquals(res.getStatusLine().getStatusCode(), 200);

    Assert.assertTrue(getServer().getContext().exists(dbName));
    getServer().getContext().drop(dbName);
  }

  @Override
  protected String getDatabaseName() {
    return "server";
  }
}

@@ -121,16 +121,44 @@
 cument;%0A
+import java.io.IOException;%0A
 import o
@@ -239,37 +239,8 @@
 t;%0A%0A
-import java.io.IOException;%0A%0A
 publ
@@ -1115,17 +1115,19 @@
 leName()
-+
+ + 
 %22testCre
@@ -1167,28 +1167,24 @@
 s =%0A        
-    
 setUserName(
@@ -1203,24 +1203,16 @@
         
-     
-   
 .setUser
@@ -1240,24 +1240,16 @@
         
-       
- 
 .post(%22s
@@ -1263,24 +1263,16 @@
 mmand%22)%0A
-        
         
@@ -1321,16 +1321,20 @@
 se %22
-+
+ + 
 dbName
-+
+ + 
 %22 pl
@@ -1358,24 +1358,16 @@
 T.JSON)%0A
-        
         

Fix code style