Created
May 29, 2019 19:20
-
-
Save Sovietaced/85a212738422fc80f02d38a6fb7f6ac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.projectfloodlight.db; | |
import static org.hamcrest.Matchers.is; | |
import static org.junit.Assert.assertThat; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.projectfloodlight.test.RepeatRule; | |
import org.restlet.Server; | |
import org.restlet.data.Protocol; | |
import org.restlet.representation.Representation; | |
import org.restlet.representation.StringRepresentation; | |
import org.restlet.representation.Variant; | |
import org.restlet.resource.ClientResource; | |
import org.restlet.resource.Get; | |
import org.restlet.resource.Put; | |
import org.restlet.resource.ServerResource; | |
public class RestletClientBug { | |
@Rule | |
public final RepeatRule rule = new RepeatRule(); | |
private Server server; | |
@Before | |
public void setup() throws Exception { | |
// Create the HTTP server and listen on port 8182 | |
server = new Server(Protocol.HTTP, 8182, FirstServerResource.class); | |
server.start(); | |
} | |
@After | |
public void teardown() throws Exception { | |
server.stop(); | |
} | |
//@Repeat(times=100) | |
@Test | |
public void testGet() throws Exception { | |
ClientResource clientResource = new ClientResource("http://localhost:8182/"); | |
Representation output = clientResource.get(); | |
System.out.println(output.getText()); | |
assertThat(clientResource.getStatus().getCode(), is(200)); | |
clientResource.release(); | |
} | |
//@Repeat(times=5) | |
@Test | |
public void testPut() throws Exception { | |
ClientResource clientResource = new ClientResource("http://localhost:8182/"); | |
Representation output = clientResource.put(new StringRepresentation("\"test\"")); | |
System.out.println(output.getText()); | |
assertThat(clientResource.getStatus().getCode(), is(200)); | |
clientResource.release(); | |
} | |
public static class FirstServerResource extends ServerResource { | |
@Override | |
@Get | |
public String toString() { | |
return "hello, world"; | |
} | |
@Put | |
public String insertDataJson(Representation entity, Variant variant) throws DBException { | |
return "put success"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment