diff --git a/src/main/java/com/javademo/resources/HelloWorld20193803103820.java b/src/main/java/com/javademo/resources/HelloWorld20193803103820.java new file mode 100644 index 0000000..0f289ad --- /dev/null +++ b/src/main/java/com/javademo/resources/HelloWorld20193803103820.java @@ -0,0 +1,45 @@ +package com.javademo.resources; + +import com.google.common.base.Optional; +import com.codahale.metrics.annotation.Timed; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import java.util.concurrent.atomic.AtomicLong; + +import java.sql.*; + +@Path("/hello-world-20193803103820") +@Produces(MediaType.APPLICATION_JSON) +public class HelloWorld20193803103820 { + private transient final String template; + private transient final String defaultName; + + public HelloWorld20193803103820(String template, String defaultName) { + this.template = template; + this.defaultName = defaultName; + } + + @GET + @Timed + public void sayHello(@QueryParam("name") Optional name) { + final String value = String.format(template, name.or(defaultName)); + } + + public double add(int x, int y){ + return (double) x+y; + } + + public Connection generateConnection(){ + //TODO: implement a connection method + return null; + } + + @GET + public void TestSQLInjection(@QueryParam("userid") Optional userId, @QueryParam("password") Optional password){ + return; + } +} \ No newline at end of file diff --git a/src/test/java/com/javademo/resources/HelloWorld20193803103820Test.java b/src/test/java/com/javademo/resources/HelloWorld20193803103820Test.java new file mode 100644 index 0000000..3a1b772 --- /dev/null +++ b/src/test/java/com/javademo/resources/HelloWorld20193803103820Test.java @@ -0,0 +1,38 @@ +package com.javademo.resources; + + +import com.google.common.base.Optional; + + + +import org.junit.*; +import static org.assertj.core.api.Assertions.assertThat; + +public class HelloWorld20193803103820Test { + private HelloWorld20193803103820 resource; + + public void setup() { + System.out.println("YAY"); + } + + + public void testDumb() { + resource = new HelloWorld20193803103820("Hello, %s", "Stranger"); + Optional empty = Optional.absent(); + Optional emptyInteger = Optional.absent(); + resource.sayHello(empty); + resource.TestSQLInjection(emptyInteger,empty); + } + + @Test + public void testAdd() { + resource = new HelloWorld20193803103820("Hello, %s", "Stranger"); + + double result = resource.add(7,9); + //assertThat("y").isEqualTo("y"); + assertThat(result).isEqualTo((double) 7+9); + } + + + +} \ No newline at end of file